symdef.pas 241 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468
  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. begin
  2528. savesize:=search_system_type('FILEREC').typedef.size;
  2529. { allocate put/get buffer in iso mode }
  2530. if m_iso in current_settings.modeswitches then
  2531. inc(savesize,typedfiledef.size);
  2532. end;
  2533. ft_untyped:
  2534. savesize:=search_system_type('FILEREC').typedef.size;
  2535. else
  2536. internalerror(2013113001);
  2537. end;
  2538. end;
  2539. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  2540. begin
  2541. inherited ppuwrite(ppufile);
  2542. ppufile.putbyte(byte(filetyp));
  2543. if filetyp=ft_typed then
  2544. ppufile.putderef(typedfiledefderef);
  2545. ppufile.writeentry(ibfiledef);
  2546. end;
  2547. function tfiledef.GetTypeName : string;
  2548. begin
  2549. case filetyp of
  2550. ft_untyped:
  2551. GetTypeName:='File';
  2552. ft_typed:
  2553. GetTypeName:='File Of '+typedfiledef.typename;
  2554. ft_text:
  2555. GetTypeName:='Text'
  2556. else
  2557. internalerror(2013113002);
  2558. end;
  2559. end;
  2560. function tfiledef.getmangledparaname : TSymStr;
  2561. begin
  2562. case filetyp of
  2563. ft_untyped:
  2564. getmangledparaname:='FILE';
  2565. ft_typed:
  2566. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  2567. ft_text:
  2568. getmangledparaname:='TEXT'
  2569. else
  2570. internalerror(2013113003);
  2571. end;
  2572. end;
  2573. {****************************************************************************
  2574. TVARIANTDEF
  2575. ****************************************************************************}
  2576. constructor tvariantdef.create(v : tvarianttype);
  2577. begin
  2578. inherited create(variantdef);
  2579. varianttype:=v;
  2580. setsize;
  2581. end;
  2582. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2583. begin
  2584. inherited ppuload(variantdef,ppufile);
  2585. varianttype:=tvarianttype(ppufile.getbyte);
  2586. setsize;
  2587. end;
  2588. function tvariantdef.getcopy : tstoreddef;
  2589. begin
  2590. result:=tvariantdef.create(varianttype);
  2591. end;
  2592. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2593. begin
  2594. inherited ppuwrite(ppufile);
  2595. ppufile.putbyte(byte(varianttype));
  2596. ppufile.writeentry(ibvariantdef);
  2597. end;
  2598. function tvariantdef.getvardef : longint;
  2599. begin
  2600. Result:=varVariant;
  2601. end;
  2602. procedure tvariantdef.setsize;
  2603. begin
  2604. {$ifdef cpu64bitaddr}
  2605. savesize:=24;
  2606. {$else cpu64bitaddr}
  2607. savesize:=16;
  2608. {$endif cpu64bitaddr}
  2609. end;
  2610. function tvariantdef.GetTypeName : string;
  2611. begin
  2612. case varianttype of
  2613. vt_normalvariant:
  2614. GetTypeName:='Variant';
  2615. vt_olevariant:
  2616. GetTypeName:='OleVariant';
  2617. else
  2618. internalerror(2013113004);
  2619. end;
  2620. end;
  2621. function tvariantdef.needs_inittable : boolean;
  2622. begin
  2623. needs_inittable:=true;
  2624. end;
  2625. function tvariantdef.is_publishable : boolean;
  2626. begin
  2627. is_publishable:=true;
  2628. end;
  2629. {****************************************************************************
  2630. TABSTRACtpointerdef
  2631. ****************************************************************************}
  2632. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  2633. begin
  2634. inherited create(dt);
  2635. pointeddef:=def;
  2636. savesize:=sizeof(pint);
  2637. end;
  2638. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2639. begin
  2640. inherited ppuload(dt,ppufile);
  2641. ppufile.getderef(pointeddefderef);
  2642. savesize:=sizeof(pint);
  2643. end;
  2644. procedure tabstractpointerdef.buildderef;
  2645. begin
  2646. inherited buildderef;
  2647. pointeddefderef.build(pointeddef);
  2648. end;
  2649. procedure tabstractpointerdef.deref;
  2650. begin
  2651. inherited deref;
  2652. pointeddef:=tdef(pointeddefderef.resolve);
  2653. end;
  2654. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2655. begin
  2656. inherited ppuwrite(ppufile);
  2657. ppufile.putderef(pointeddefderef);
  2658. end;
  2659. {****************************************************************************
  2660. tpointerdef
  2661. ****************************************************************************}
  2662. constructor tpointerdef.create(def:tdef);
  2663. begin
  2664. inherited create(pointerdef,def);
  2665. {$ifdef x86}
  2666. x86pointertyp := default_x86_data_pointer_type;
  2667. {$endif x86}
  2668. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2669. end;
  2670. {$ifdef x86}
  2671. constructor tpointerdef.createx86(def: tdef; x86typ: tx86pointertyp);
  2672. begin
  2673. inherited create(pointerdef,def);
  2674. x86pointertyp := x86typ;
  2675. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2676. end;
  2677. {$endif x86}
  2678. function tpointerdef.size: asizeint;
  2679. begin
  2680. {$ifdef x86}
  2681. if x86pointertyp in [x86pt_far,x86pt_huge] then
  2682. result:=sizeof(pint)+2
  2683. else
  2684. {$endif x86}
  2685. result:=sizeof(pint);
  2686. end;
  2687. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2688. begin
  2689. inherited ppuload(pointerdef,ppufile);
  2690. {$ifdef x86}
  2691. x86pointertyp:=tx86pointertyp(ppufile.getbyte);
  2692. {$endif x86}
  2693. has_pointer_math:=(ppufile.getbyte<>0);
  2694. end;
  2695. function tpointerdef.getcopy : tstoreddef;
  2696. begin
  2697. { don't use direct pointeddef if it is a forwarddef because in other case
  2698. one of them will be destroyed on forward type resolve and the second will
  2699. point to garbage }
  2700. if pointeddef.typ=forwarddef then
  2701. result:=tpointerdef.create(tforwarddef(pointeddef).getcopy)
  2702. else
  2703. result:=tpointerdef.create(pointeddef);
  2704. {$ifdef x86}
  2705. tpointerdef(result).x86pointertyp:=x86pointertyp;
  2706. {$endif x86}
  2707. tpointerdef(result).has_pointer_math:=has_pointer_math;
  2708. tpointerdef(result).savesize:=savesize;
  2709. end;
  2710. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2711. begin
  2712. inherited ppuwrite(ppufile);
  2713. {$ifdef x86}
  2714. ppufile.putbyte(byte(x86pointertyp));
  2715. {$endif x86}
  2716. ppufile.putbyte(byte(has_pointer_math));
  2717. ppufile.writeentry(ibpointerdef);
  2718. end;
  2719. function tpointerdef.GetTypeName : string;
  2720. begin
  2721. {$ifdef x86}
  2722. if x86pointertyp = default_x86_data_pointer_type then
  2723. GetTypeName:='^'+pointeddef.typename
  2724. else
  2725. case x86pointertyp of
  2726. x86pt_near: GetTypeName:='^'+pointeddef.typename+';near';
  2727. x86pt_near_cs: GetTypeName:='^'+pointeddef.typename+';near ''CS''';
  2728. x86pt_near_ds: GetTypeName:='^'+pointeddef.typename+';near ''DS''';
  2729. x86pt_near_ss: GetTypeName:='^'+pointeddef.typename+';near ''SS''';
  2730. x86pt_near_es: GetTypeName:='^'+pointeddef.typename+';near ''ES''';
  2731. x86pt_near_fs: GetTypeName:='^'+pointeddef.typename+';near ''FS''';
  2732. x86pt_near_gs: GetTypeName:='^'+pointeddef.typename+';near ''GS''';
  2733. x86pt_far: GetTypeName:='^'+pointeddef.typename+';far';
  2734. x86pt_huge: GetTypeName:='^'+pointeddef.typename+';huge';
  2735. else
  2736. internalerror(2013050301);
  2737. end;
  2738. {$else x86}
  2739. GetTypeName:='^'+pointeddef.typename;
  2740. {$endif x86}
  2741. end;
  2742. {****************************************************************************
  2743. TCLASSREFDEF
  2744. ****************************************************************************}
  2745. constructor tclassrefdef.create(def:tdef);
  2746. begin
  2747. inherited create(classrefdef,def);
  2748. end;
  2749. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2750. begin
  2751. inherited ppuload(classrefdef,ppufile);
  2752. end;
  2753. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2754. begin
  2755. inherited ppuwrite(ppufile);
  2756. ppufile.writeentry(ibclassrefdef);
  2757. end;
  2758. function tclassrefdef.getcopy:tstoreddef;
  2759. begin
  2760. if pointeddef.typ=forwarddef then
  2761. result:=tclassrefdef.create(tforwarddef(pointeddef).getcopy)
  2762. else
  2763. result:=tclassrefdef.create(pointeddef);
  2764. tclassrefdef(result).savesize:=savesize;
  2765. end;
  2766. function tclassrefdef.GetTypeName : string;
  2767. begin
  2768. GetTypeName:='Class Of '+pointeddef.typename;
  2769. end;
  2770. function tclassrefdef.is_publishable : boolean;
  2771. begin
  2772. result:=true;
  2773. end;
  2774. function tclassrefdef.rtti_mangledname(rt: trttitype): string;
  2775. begin
  2776. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  2777. result:=inherited rtti_mangledname(rt)
  2778. else
  2779. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  2780. end;
  2781. procedure tclassrefdef.register_created_object_type;
  2782. begin
  2783. tobjectdef(pointeddef).register_created_classref_type;
  2784. end;
  2785. {***************************************************************************
  2786. TSETDEF
  2787. ***************************************************************************}
  2788. constructor tsetdef.create(def:tdef;low, high : asizeint);
  2789. var
  2790. setallocbits: aint;
  2791. packedsavesize: aint;
  2792. begin
  2793. inherited create(setdef);
  2794. elementdef:=def;
  2795. setmax:=high;
  2796. if (current_settings.setalloc=0) then
  2797. begin
  2798. setbase:=0;
  2799. if (high<32) then
  2800. savesize:=Sizeof(longint)
  2801. else if (high<256) then
  2802. savesize:=32
  2803. else
  2804. savesize:=(high+7) div 8
  2805. end
  2806. else
  2807. begin
  2808. setallocbits:=current_settings.setalloc*8;
  2809. setbase:=low and not(setallocbits-1);
  2810. packedsavesize:=current_settings.setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  2811. savesize:=packedsavesize;
  2812. if savesize=3 then
  2813. savesize:=4;
  2814. end;
  2815. end;
  2816. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2817. begin
  2818. inherited ppuload(setdef,ppufile);
  2819. ppufile.getderef(elementdefderef);
  2820. savesize:=ppufile.getaint;
  2821. setbase:=ppufile.getaint;
  2822. setmax:=ppufile.getaint;
  2823. end;
  2824. function tsetdef.getcopy : tstoreddef;
  2825. begin
  2826. result:=tsetdef.create(elementdef,setbase,setmax);
  2827. { the copy might have been created with a different setalloc setting }
  2828. tsetdef(result).savesize:=savesize;
  2829. end;
  2830. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2831. begin
  2832. inherited ppuwrite(ppufile);
  2833. ppufile.putderef(elementdefderef);
  2834. ppufile.putaint(savesize);
  2835. ppufile.putaint(setbase);
  2836. ppufile.putaint(setmax);
  2837. ppufile.writeentry(ibsetdef);
  2838. end;
  2839. procedure tsetdef.buildderef;
  2840. begin
  2841. inherited buildderef;
  2842. elementdefderef.build(elementdef);
  2843. end;
  2844. procedure tsetdef.deref;
  2845. begin
  2846. inherited deref;
  2847. elementdef:=tdef(elementdefderef.resolve);
  2848. end;
  2849. function tsetdef.is_publishable : boolean;
  2850. begin
  2851. is_publishable:=savesize in [1,2,4];
  2852. end;
  2853. function tsetdef.GetTypeName : string;
  2854. begin
  2855. if assigned(elementdef) then
  2856. GetTypeName:='Set Of '+elementdef.typename
  2857. else
  2858. GetTypeName:='Empty Set';
  2859. end;
  2860. {***************************************************************************
  2861. TFORMALDEF
  2862. ***************************************************************************}
  2863. constructor tformaldef.create(Atyped:boolean);
  2864. begin
  2865. inherited create(formaldef);
  2866. typed:=Atyped;
  2867. savesize:=0;
  2868. end;
  2869. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2870. begin
  2871. inherited ppuload(formaldef,ppufile);
  2872. typed:=boolean(ppufile.getbyte);
  2873. savesize:=0;
  2874. end;
  2875. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2876. begin
  2877. inherited ppuwrite(ppufile);
  2878. ppufile.putbyte(byte(typed));
  2879. ppufile.writeentry(ibformaldef);
  2880. end;
  2881. function tformaldef.GetTypeName : string;
  2882. begin
  2883. if typed then
  2884. GetTypeName:='<Typed formal type>'
  2885. else
  2886. GetTypeName:='<Formal type>';
  2887. end;
  2888. {***************************************************************************
  2889. TARRAYDEF
  2890. ***************************************************************************}
  2891. constructor tarraydef.create(l,h:asizeint;def:tdef);
  2892. begin
  2893. inherited create(arraydef);
  2894. lowrange:=l;
  2895. highrange:=h;
  2896. rangedef:=def;
  2897. _elementdef:=nil;
  2898. arrayoptions:=[];
  2899. symtable:=tarraysymtable.create(self);
  2900. end;
  2901. destructor tarraydef.destroy;
  2902. begin
  2903. symtable.free;
  2904. symtable:=nil;
  2905. inherited;
  2906. end;
  2907. constructor tarraydef.create_from_pointer(def:tdef);
  2908. begin
  2909. { use -1 so that the elecount will not overflow }
  2910. self.create(0,high(asizeint)-1,ptrsinttype);
  2911. arrayoptions:=[ado_IsConvertedPointer];
  2912. setelementdef(def);
  2913. end;
  2914. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2915. begin
  2916. inherited ppuload(arraydef,ppufile);
  2917. { the addresses are calculated later }
  2918. ppufile.getderef(_elementdefderef);
  2919. ppufile.getderef(rangedefderef);
  2920. lowrange:=ppufile.getasizeint;
  2921. highrange:=ppufile.getasizeint;
  2922. ppufile.getsmallset(arrayoptions);
  2923. symtable:=tarraysymtable.create(self);
  2924. tarraysymtable(symtable).ppuload(ppufile)
  2925. end;
  2926. function tarraydef.getcopy : tstoreddef;
  2927. begin
  2928. result:=tarraydef.create(lowrange,highrange,rangedef);
  2929. tarraydef(result).arrayoptions:=arrayoptions;
  2930. tarraydef(result)._elementdef:=_elementdef;
  2931. end;
  2932. procedure tarraydef.buildderef;
  2933. begin
  2934. inherited buildderef;
  2935. tarraysymtable(symtable).buildderef;
  2936. _elementdefderef.build(_elementdef);
  2937. rangedefderef.build(rangedef);
  2938. end;
  2939. procedure tarraydef.deref;
  2940. begin
  2941. inherited deref;
  2942. tarraysymtable(symtable).deref;
  2943. _elementdef:=tdef(_elementdefderef.resolve);
  2944. rangedef:=tdef(rangedefderef.resolve);
  2945. fillgenericparas(symtable);
  2946. end;
  2947. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2948. begin
  2949. inherited ppuwrite(ppufile);
  2950. ppufile.putderef(_elementdefderef);
  2951. ppufile.putderef(rangedefderef);
  2952. ppufile.putasizeint(lowrange);
  2953. ppufile.putasizeint(highrange);
  2954. ppufile.putsmallset(arrayoptions);
  2955. ppufile.writeentry(ibarraydef);
  2956. tarraysymtable(symtable).ppuwrite(ppufile);
  2957. end;
  2958. function tarraydef.elesize : asizeint;
  2959. begin
  2960. if (ado_IsBitPacked in arrayoptions) then
  2961. internalerror(2006080101);
  2962. if assigned(_elementdef) then
  2963. result:=_elementdef.size
  2964. else
  2965. result:=0;
  2966. end;
  2967. function tarraydef.elepackedbitsize : asizeint;
  2968. begin
  2969. if not(ado_IsBitPacked in arrayoptions) then
  2970. internalerror(2006080102);
  2971. if assigned(_elementdef) then
  2972. result:=_elementdef.packedbitsize
  2973. else
  2974. result:=0;
  2975. end;
  2976. function tarraydef.elecount : asizeuint;
  2977. var
  2978. qhigh,qlow : qword;
  2979. begin
  2980. if ado_IsDynamicArray in arrayoptions then
  2981. begin
  2982. result:=0;
  2983. exit;
  2984. end;
  2985. if (highrange>0) and (lowrange<0) then
  2986. begin
  2987. qhigh:=highrange;
  2988. qlow:=qword(-lowrange);
  2989. { prevent overflow, return 0 to indicate overflow }
  2990. if qhigh+qlow>qword(high(asizeint)-1) then
  2991. result:=0
  2992. else
  2993. result:=qhigh+qlow+1;
  2994. end
  2995. else
  2996. result:=int64(highrange)-lowrange+1;
  2997. end;
  2998. function tarraydef.size : asizeint;
  2999. var
  3000. cachedelecount : asizeuint;
  3001. cachedelesize : asizeint;
  3002. begin
  3003. if ado_IsDynamicArray in arrayoptions then
  3004. begin
  3005. size:=sizeof(pint);
  3006. exit;
  3007. end;
  3008. { Tarraydef.size may never be called for an open array! }
  3009. if highrange<lowrange then
  3010. internalerror(99080501);
  3011. if not (ado_IsBitPacked in arrayoptions) then
  3012. cachedelesize:=elesize
  3013. else
  3014. cachedelesize := elepackedbitsize;
  3015. cachedelecount:=elecount;
  3016. if (cachedelesize = 0) then
  3017. begin
  3018. size := 0;
  3019. exit;
  3020. end;
  3021. if (cachedelecount = 0) then
  3022. begin
  3023. size := -1;
  3024. exit;
  3025. end;
  3026. { prevent overflow, return -1 to indicate overflow }
  3027. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  3028. if (cachedelecount > asizeuint(high(asizeint))) or
  3029. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  3030. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  3031. accessing the array, see ncgmem (PFV) }
  3032. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  3033. begin
  3034. result:=-1;
  3035. exit;
  3036. end;
  3037. result:=cachedelesize*asizeint(cachedelecount);
  3038. if (ado_IsBitPacked in arrayoptions) then
  3039. { can't just add 7 and divide by 8, because that may overflow }
  3040. result:=result div 8 + ord((result mod 8)<>0);
  3041. end;
  3042. procedure tarraydef.setelementdef(def:tdef);
  3043. begin
  3044. _elementdef:=def;
  3045. if not(
  3046. (ado_IsDynamicArray in arrayoptions) or
  3047. (ado_IsConvertedPointer in arrayoptions) or
  3048. (highrange<lowrange)
  3049. ) and
  3050. (size=-1) then
  3051. Message(sym_e_segment_too_large);
  3052. end;
  3053. function tarraydef.alignment : shortint;
  3054. begin
  3055. { alignment of dyn. arrays doesn't depend on the element size }
  3056. if (ado_IsDynamicArray in arrayoptions) then
  3057. alignment:=size_2_align(sizeof(pint))
  3058. { alignment is the target alignment for the used load size }
  3059. else if (ado_IsBitPacked in arrayoptions) and
  3060. (elementdef.typ in [enumdef,orddef]) then
  3061. alignment:=cgsize_orddef(int_cgsize(packedbitsloadsize(elepackedbitsize))).alignment
  3062. { alignment is the alignment of the elements }
  3063. else
  3064. alignment:=elementdef.alignment
  3065. end;
  3066. function tarraydef.needs_inittable : boolean;
  3067. begin
  3068. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  3069. end;
  3070. function tarraydef.needs_separate_initrtti : boolean;
  3071. begin
  3072. if ado_IsBitPacked in arrayoptions then
  3073. result:=false
  3074. else
  3075. result:=elementdef.needs_separate_initrtti;
  3076. end;
  3077. function tarraydef.GetTypeName : string;
  3078. begin
  3079. if (ado_IsConstString in arrayoptions) then
  3080. result:='Constant String'
  3081. else if (ado_isarrayofconst in arrayoptions) or
  3082. (ado_isConstructor in arrayoptions) then
  3083. begin
  3084. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  3085. GetTypeName:='Array Of Const'
  3086. else
  3087. GetTypeName:='{Array Of Const/Constant Open} Array of '+elementdef.typename;
  3088. end
  3089. else if (ado_IsDynamicArray in arrayoptions) then
  3090. GetTypeName:='{Dynamic} Array Of '+elementdef.typename
  3091. else if ((highrange=-1) and (lowrange=0)) then
  3092. GetTypeName:='{Open} Array Of '+elementdef.typename
  3093. else
  3094. begin
  3095. result := '';
  3096. if (ado_IsBitPacked in arrayoptions) then
  3097. result:='BitPacked ';
  3098. if rangedef.typ=enumdef then
  3099. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  3100. else
  3101. result:=result+'Array['+tostr(lowrange)+'..'+
  3102. tostr(highrange)+'] Of '+elementdef.typename
  3103. end;
  3104. end;
  3105. function tarraydef.getmangledparaname : TSymStr;
  3106. begin
  3107. if ado_isarrayofconst in arrayoptions then
  3108. getmangledparaname:='array_of_const'
  3109. else
  3110. if ((highrange=-1) and (lowrange=0)) then
  3111. getmangledparaname:='array_of_'+elementdef.mangledparaname
  3112. else
  3113. internalerror(200204176);
  3114. end;
  3115. function tarraydef.is_publishable : boolean;
  3116. begin
  3117. Result:=ado_IsDynamicArray in arrayoptions;
  3118. end;
  3119. {***************************************************************************
  3120. tabstractrecorddef
  3121. ***************************************************************************}
  3122. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp);
  3123. begin
  3124. inherited create(dt);
  3125. objname:=stringdup(upper(n));
  3126. objrealname:=stringdup(n);
  3127. objectoptions:=[];
  3128. if assigned(current_module.namespace) then
  3129. begin
  3130. import_lib:=stringdup(current_module.namespace^);
  3131. replace(import_lib^,'.','/');
  3132. end;
  3133. end;
  3134. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3135. begin
  3136. inherited ppuload(dt,ppufile);
  3137. objrealname:=stringdup(ppufile.getstring);
  3138. objname:=stringdup(upper(objrealname^));
  3139. import_lib:=stringdup(ppufile.getstring);
  3140. { only used for external C++ classes and Java classes/records }
  3141. if (import_lib^='') then
  3142. stringdispose(import_lib);
  3143. ppufile.getsmallset(objectoptions);
  3144. end;
  3145. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  3146. begin
  3147. inherited ppuwrite(ppufile);
  3148. ppufile.putstring(objrealname^);
  3149. if assigned(import_lib) then
  3150. ppufile.putstring(import_lib^)
  3151. else
  3152. ppufile.putstring('');
  3153. ppufile.putsmallset(objectoptions);
  3154. end;
  3155. destructor tabstractrecorddef.destroy;
  3156. begin
  3157. stringdispose(objname);
  3158. stringdispose(objrealname);
  3159. stringdispose(import_lib);
  3160. tcinitcode.free;
  3161. inherited destroy;
  3162. end;
  3163. procedure tabstractrecorddef.check_forwards;
  3164. begin
  3165. { the defs of a copied def are defined for the original type only }
  3166. if not(df_copied_def in defoptions) then
  3167. tstoredsymtable(symtable).check_forwards;
  3168. end;
  3169. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  3170. var
  3171. i: longint;
  3172. sym: tsym;
  3173. begin
  3174. for i:=0 to symtable.SymList.Count-1 do
  3175. begin
  3176. sym:=tsym(symtable.SymList[i]);
  3177. if sym.typ=procsym then
  3178. begin
  3179. result:=tprocsym(sym).find_procdef_bytype(pt);
  3180. if assigned(result) then
  3181. exit;
  3182. end;
  3183. end;
  3184. result:=nil;
  3185. end;
  3186. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  3187. begin
  3188. if t=gs_record then
  3189. GetSymtable:=symtable
  3190. else
  3191. GetSymtable:=nil;
  3192. end;
  3193. function tabstractrecorddef.is_packed:boolean;
  3194. begin
  3195. result:=tabstractrecordsymtable(symtable).is_packed;
  3196. end;
  3197. function tabstractrecorddef.RttiName: string;
  3198. begin
  3199. Result:=OwnerHierarchyName+objrealname^;
  3200. end;
  3201. function tabstractrecorddef.search_enumerator_get: tprocdef;
  3202. var
  3203. sym : tsym;
  3204. i : integer;
  3205. pd : tprocdef;
  3206. hashedid : THashedIDString;
  3207. begin
  3208. result:=nil;
  3209. hashedid.id:='GETENUMERATOR';
  3210. sym:=tsym(symtable.FindWithHash(hashedid));
  3211. if assigned(sym) and (sym.typ=procsym) then
  3212. begin
  3213. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  3214. begin
  3215. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  3216. if (pd.proctypeoption = potype_function) and
  3217. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  3218. (pd.visibility >= vis_public) then
  3219. begin
  3220. result:=pd;
  3221. exit;
  3222. end;
  3223. end;
  3224. end;
  3225. end;
  3226. function tabstractrecorddef.search_enumerator_move: tprocdef;
  3227. var
  3228. sym : tsym;
  3229. i : integer;
  3230. pd : tprocdef;
  3231. hashedid : THashedIDString;
  3232. begin
  3233. result:=nil;
  3234. // first search for po_enumerator_movenext method modifier
  3235. // then search for public function MoveNext: Boolean
  3236. for i:=0 to symtable.SymList.Count-1 do
  3237. begin
  3238. sym:=TSym(symtable.SymList[i]);
  3239. if (sym.typ=procsym) then
  3240. begin
  3241. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  3242. if assigned(pd) then
  3243. begin
  3244. result:=pd;
  3245. exit;
  3246. end;
  3247. end;
  3248. end;
  3249. hashedid.id:='MOVENEXT';
  3250. sym:=tsym(symtable.FindWithHash(hashedid));
  3251. if assigned(sym) and (sym.typ=procsym) then
  3252. begin
  3253. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  3254. begin
  3255. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  3256. if (pd.proctypeoption = potype_function) and
  3257. is_boolean(pd.returndef) and
  3258. (pd.minparacount = 0) and
  3259. (pd.visibility >= vis_public) then
  3260. begin
  3261. result:=pd;
  3262. exit;
  3263. end;
  3264. end;
  3265. end;
  3266. end;
  3267. function tabstractrecorddef.search_enumerator_current: tsym;
  3268. var
  3269. sym: tsym;
  3270. i: integer;
  3271. hashedid : THashedIDString;
  3272. begin
  3273. result:=nil;
  3274. // first search for ppo_enumerator_current property modifier
  3275. // then search for public property Current
  3276. for i:=0 to symtable.SymList.Count-1 do
  3277. begin
  3278. sym:=TSym(symtable.SymList[i]);
  3279. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  3280. begin
  3281. result:=sym;
  3282. exit;
  3283. end;
  3284. end;
  3285. hashedid.id:='CURRENT';
  3286. sym:=tsym(symtable.FindWithHash(hashedid));
  3287. if assigned(sym) and (sym.typ=propertysym) and
  3288. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  3289. begin
  3290. result:=sym;
  3291. exit;
  3292. end;
  3293. end;
  3294. function tabstractrecorddef.jvm_full_typename(with_package_name: boolean): string;
  3295. var
  3296. st: tsymtable;
  3297. enclosingdef: tdef;
  3298. begin
  3299. if typ=objectdef then
  3300. result:=tobjectdef(self).objextname^
  3301. else if assigned(typesym) then
  3302. result:=typesym.realname
  3303. { have to generate anonymous nested type in current unit/class/record }
  3304. else
  3305. internalerror(2011032601);
  3306. { in case of specializations, add some extras to prevent name conflicts
  3307. with nested classes }
  3308. if df_specialization in defoptions then
  3309. result:='$'+result+'$specialization$';
  3310. st:=owner;
  3311. while assigned(st) and
  3312. (st.symtabletype in [objectsymtable,recordsymtable,localsymtable]) do
  3313. begin
  3314. { nested classes are named as "OuterClass$InnerClass" }
  3315. enclosingdef:=tdef(st.defowner);
  3316. if enclosingdef.typ=procdef then
  3317. result:=result+tprocdef(enclosingdef).procsym.realname+'$$'+tostr(tprocdef(enclosingdef).procsym.symid)+'$'
  3318. else if enclosingdef.typ=objectdef then
  3319. result:=tobjectdef(enclosingdef).objextname^+'$'+result
  3320. else if assigned(enclosingdef.typesym) then
  3321. result:=enclosingdef.typesym.realname+'$'+result
  3322. else
  3323. internalerror(2011060305);
  3324. st:=enclosingdef.owner;
  3325. end;
  3326. if with_package_name and
  3327. assigned(import_lib) then
  3328. result:=import_lib^+'/'+result;
  3329. end;
  3330. function tabstractrecorddef.contains_float_field: boolean;
  3331. var
  3332. i : longint;
  3333. begin
  3334. result:=true;
  3335. for i:=0 to symtable.symlist.count-1 do
  3336. begin
  3337. if tsym(symtable.symlist[i]).typ<>fieldvarsym then
  3338. continue;
  3339. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) and
  3340. tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).is_fpuregable then
  3341. exit;
  3342. end;
  3343. result:=false;
  3344. end;
  3345. {***************************************************************************
  3346. trecorddef
  3347. ***************************************************************************}
  3348. constructor trecorddef.create(const n:string; p:TSymtable);
  3349. begin
  3350. inherited create(n,recorddef);
  3351. symtable:=p;
  3352. { we can own the symtable only if nobody else owns a copy so far }
  3353. if symtable.refcount=1 then
  3354. symtable.defowner:=self;
  3355. isunion:=false;
  3356. end;
  3357. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  3358. procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);
  3359. var
  3360. i,j : longint;
  3361. begin
  3362. if ppufile.getbyte=1 then
  3363. begin
  3364. new(variantrecdesc);
  3365. ppufile.getderef(variantrecdesc^.variantselectorderef);
  3366. SetLength(variantrecdesc^.branches,ppufile.getasizeint);
  3367. for i:=0 to high(variantrecdesc^.branches) do
  3368. begin
  3369. SetLength(variantrecdesc^.branches[i].values,ppufile.getasizeint);
  3370. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3371. variantrecdesc^.branches[i].values[j]:=ppufile.getexprint;
  3372. readvariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3373. end;
  3374. end
  3375. else
  3376. variantrecdesc:=nil;
  3377. end;
  3378. begin
  3379. inherited ppuload(recorddef,ppufile);
  3380. if df_copied_def in defoptions then
  3381. ppufile.getderef(cloneddefderef)
  3382. else
  3383. begin
  3384. symtable:=trecordsymtable.create(objrealname^,0);
  3385. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  3386. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  3387. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  3388. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  3389. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  3390. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  3391. trecordsymtable(symtable).ppuload(ppufile);
  3392. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3393. but because iso mode supports no units, there is no need to store the variantrecdesc
  3394. in the ppu
  3395. }
  3396. // readvariantrecdesc(variantrecdesc);
  3397. { requires usefieldalignment to be set }
  3398. symtable.defowner:=self;
  3399. end;
  3400. isunion:=false;
  3401. end;
  3402. destructor trecorddef.destroy;
  3403. begin
  3404. if assigned(symtable) then
  3405. begin
  3406. symtable.free;
  3407. symtable:=nil;
  3408. end;
  3409. inherited destroy;
  3410. end;
  3411. function trecorddef.getcopy : tstoreddef;
  3412. begin
  3413. result:=trecorddef.create(objrealname^,symtable.getcopy);
  3414. trecorddef(result).isunion:=isunion;
  3415. include(trecorddef(result).defoptions,df_copied_def);
  3416. if assigned(tcinitcode) then
  3417. trecorddef(result).tcinitcode:=tcinitcode.getcopy;
  3418. if assigned(import_lib) then
  3419. trecorddef(result).import_lib:=stringdup(import_lib^);
  3420. end;
  3421. function trecorddef.needs_inittable : boolean;
  3422. begin
  3423. needs_inittable:=trecordsymtable(symtable).needs_init_final
  3424. end;
  3425. function trecorddef.needs_separate_initrtti : boolean;
  3426. begin
  3427. result:=true;
  3428. end;
  3429. procedure trecorddef.buildderef;
  3430. begin
  3431. inherited buildderef;
  3432. if df_copied_def in defoptions then
  3433. cloneddefderef.build(symtable.defowner)
  3434. else
  3435. tstoredsymtable(symtable).buildderef;
  3436. end;
  3437. procedure trecorddef.buildderefimpl;
  3438. begin
  3439. inherited buildderefimpl;
  3440. if not (df_copied_def in defoptions) then
  3441. tstoredsymtable(symtable).buildderefimpl;
  3442. end;
  3443. procedure trecorddef.deref;
  3444. begin
  3445. inherited deref;
  3446. { now dereference the definitions }
  3447. if df_copied_def in defoptions then
  3448. begin
  3449. cloneddef:=trecorddef(cloneddefderef.resolve);
  3450. symtable:=cloneddef.symtable.getcopy;
  3451. end
  3452. else
  3453. tstoredsymtable(symtable).deref;
  3454. fillgenericparas(symtable);
  3455. { assign TGUID? load only from system unit }
  3456. if not(assigned(rec_tguid)) and
  3457. (upper(typename)='TGUID') and
  3458. assigned(owner) and
  3459. assigned(owner.name) and
  3460. (owner.name^='SYSTEM') then
  3461. rec_tguid:=self;
  3462. { assign JMP_BUF? load only from system unit }
  3463. if not(assigned(rec_jmp_buf)) and
  3464. (upper(typename)='JMP_BUF') and
  3465. assigned(owner) and
  3466. assigned(owner.name) and
  3467. (owner.name^='SYSTEM') then
  3468. rec_jmp_buf:=self;
  3469. end;
  3470. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  3471. procedure writevariantrecdesc(variantrecdesc : pvariantrecdesc);
  3472. var
  3473. i,j : longint;
  3474. begin
  3475. if assigned(variantrecdesc) then
  3476. begin
  3477. ppufile.putbyte(1);
  3478. ppufile.putderef(variantrecdesc^.variantselectorderef);
  3479. ppufile.putasizeint(length(variantrecdesc^.branches));
  3480. for i:=0 to high(variantrecdesc^.branches) do
  3481. begin
  3482. ppufile.putasizeint(length(variantrecdesc^.branches[i].values));
  3483. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3484. ppufile.putexprint(variantrecdesc^.branches[i].values[j]);
  3485. writevariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3486. end;
  3487. end
  3488. else
  3489. ppufile.putbyte(0);
  3490. end;
  3491. begin
  3492. inherited ppuwrite(ppufile);
  3493. if df_copied_def in defoptions then
  3494. ppufile.putderef(cloneddefderef)
  3495. else
  3496. begin
  3497. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  3498. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  3499. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  3500. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  3501. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  3502. ppufile.putword(trecordsymtable(symtable).paddingsize);
  3503. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3504. but because iso mode supports no units, there is no need to store the variantrecdesc
  3505. in the ppu
  3506. }
  3507. // writevariantrecdesc(variantrecdesc);
  3508. end;
  3509. ppufile.writeentry(ibrecorddef);
  3510. if not(df_copied_def in defoptions) then
  3511. trecordsymtable(symtable).ppuwrite(ppufile);
  3512. end;
  3513. function trecorddef.size:asizeint;
  3514. begin
  3515. result:=trecordsymtable(symtable).datasize;
  3516. end;
  3517. function trecorddef.alignment:shortint;
  3518. begin
  3519. alignment:=trecordsymtable(symtable).recordalignment;
  3520. end;
  3521. function trecorddef.padalignment:shortint;
  3522. begin
  3523. padalignment := trecordsymtable(symtable).padalignment;
  3524. end;
  3525. function trecorddef.GetTypeName : string;
  3526. begin
  3527. GetTypeName:='<record type>'
  3528. end;
  3529. {***************************************************************************
  3530. TABSTRACTPROCDEF
  3531. ***************************************************************************}
  3532. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  3533. begin
  3534. inherited create(dt);
  3535. parast:=tparasymtable.create(self,level);
  3536. paras:=nil;
  3537. minparacount:=0;
  3538. maxparacount:=0;
  3539. proctypeoption:=potype_none;
  3540. proccalloption:=pocall_none;
  3541. procoptions:=[];
  3542. {$ifdef i8086}
  3543. if current_settings.x86memorymodel in x86_far_code_models then
  3544. procoptions:=procoptions+[po_far];
  3545. {$endif i8086}
  3546. returndef:=voidtype;
  3547. savesize:=sizeof(pint);
  3548. callerargareasize:=0;
  3549. calleeargareasize:=0;
  3550. has_paraloc_info:=callnoside;
  3551. funcretloc[callerside].init;
  3552. funcretloc[calleeside].init;
  3553. check_mark_as_nested;
  3554. end;
  3555. destructor tabstractprocdef.destroy;
  3556. begin
  3557. if assigned(paras) then
  3558. begin
  3559. {$ifdef MEMDEBUG}
  3560. memprocpara.start;
  3561. {$endif MEMDEBUG}
  3562. paras.free;
  3563. paras:=nil;
  3564. {$ifdef MEMDEBUG}
  3565. memprocpara.stop;
  3566. {$endif MEMDEBUG}
  3567. end;
  3568. if assigned(parast) then
  3569. begin
  3570. {$ifdef MEMDEBUG}
  3571. memprocparast.start;
  3572. {$endif MEMDEBUG}
  3573. parast.free;
  3574. parast:=nil;
  3575. {$ifdef MEMDEBUG}
  3576. memprocparast.stop;
  3577. {$endif MEMDEBUG}
  3578. end;
  3579. funcretloc[callerside].done;
  3580. funcretloc[calleeside].done;
  3581. inherited destroy;
  3582. end;
  3583. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  3584. begin
  3585. if (tsym(p).typ<>paravarsym) then
  3586. exit;
  3587. inc(plongint(arg)^);
  3588. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  3589. begin
  3590. if not assigned(tparavarsym(p).defaultconstsym) then
  3591. inc(minparacount);
  3592. inc(maxparacount);
  3593. end;
  3594. end;
  3595. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  3596. begin
  3597. if (tsym(p).typ<>paravarsym) then
  3598. exit;
  3599. paras.add(p);
  3600. end;
  3601. procedure tabstractprocdef.calcparas;
  3602. var
  3603. paracount : longint;
  3604. begin
  3605. { This can already be assigned when
  3606. we need to reresolve this unit (PFV) }
  3607. if assigned(paras) then
  3608. paras.free;
  3609. paras:=tparalist.create(false);
  3610. paracount:=0;
  3611. minparacount:=0;
  3612. maxparacount:=0;
  3613. parast.SymList.ForEachCall(@count_para,@paracount);
  3614. paras.capacity:=paracount;
  3615. { Insert parameters in table }
  3616. parast.SymList.ForEachCall(@insert_para,nil);
  3617. { Order parameters }
  3618. paras.sortparas;
  3619. end;
  3620. procedure tabstractprocdef.buildderef;
  3621. begin
  3622. { released procdef? }
  3623. if not assigned(parast) then
  3624. exit;
  3625. inherited buildderef;
  3626. returndefderef.build(returndef);
  3627. if po_explicitparaloc in procoptions then
  3628. funcretloc[callerside].buildderef;
  3629. { parast }
  3630. tparasymtable(parast).buildderef;
  3631. end;
  3632. procedure tabstractprocdef.deref;
  3633. begin
  3634. inherited deref;
  3635. returndef:=tdef(returndefderef.resolve);
  3636. if po_explicitparaloc in procoptions then
  3637. begin
  3638. funcretloc[callerside].deref;
  3639. has_paraloc_info:=callerside;
  3640. end
  3641. else
  3642. begin
  3643. { deref is called after loading from a ppu, but also after another
  3644. unit has been reloaded/recompiled and all references must be
  3645. re-resolved. Since the funcretloc contains a reference to a tdef,
  3646. reset it so that we won't try to access the stale def }
  3647. funcretloc[callerside].init;
  3648. has_paraloc_info:=callnoside;
  3649. end;
  3650. { parast }
  3651. tparasymtable(parast).deref;
  3652. { recalculated parameters }
  3653. calcparas;
  3654. fillgenericparas(parast);
  3655. end;
  3656. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3657. begin
  3658. inherited ppuload(dt,ppufile);
  3659. parast:=nil;
  3660. Paras:=nil;
  3661. minparacount:=0;
  3662. maxparacount:=0;
  3663. ppufile.getderef(returndefderef);
  3664. { TODO: remove fpu_used loading}
  3665. ppufile.getbyte;
  3666. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3667. proccalloption:=tproccalloption(ppufile.getbyte);
  3668. ppufile.getnormalset(procoptions);
  3669. funcretloc[callerside].init;
  3670. if po_explicitparaloc in procoptions then
  3671. funcretloc[callerside].ppuload(ppufile);
  3672. savesize:=sizeof(pint);
  3673. if (po_explicitparaloc in procoptions) then
  3674. has_paraloc_info:=callerside;
  3675. end;
  3676. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3677. var
  3678. oldintfcrc : boolean;
  3679. begin
  3680. { released procdef? }
  3681. if not assigned(parast) then
  3682. exit;
  3683. inherited ppuwrite(ppufile);
  3684. ppufile.putderef(returndefderef);
  3685. oldintfcrc:=ppufile.do_interface_crc;
  3686. ppufile.do_interface_crc:=false;
  3687. ppufile.putbyte(0);
  3688. ppufile.putbyte(ord(proctypeoption));
  3689. ppufile.putbyte(ord(proccalloption));
  3690. ppufile.putnormalset(procoptions);
  3691. ppufile.do_interface_crc:=oldintfcrc;
  3692. if (po_explicitparaloc in procoptions) then
  3693. funcretloc[callerside].ppuwrite(ppufile);
  3694. end;
  3695. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  3696. var
  3697. hs,s : ansistring;
  3698. hp : TParavarsym;
  3699. hpc : tconstsym;
  3700. first : boolean;
  3701. i : integer;
  3702. begin
  3703. s:='';
  3704. first:=true;
  3705. for i:=0 to paras.count-1 do
  3706. begin
  3707. hp:=tparavarsym(paras[i]);
  3708. if not(vo_is_hidden_para in hp.varoptions) or
  3709. (pno_showhidden in pno) then
  3710. begin
  3711. if first then
  3712. begin
  3713. s:=s+'(';
  3714. first:=false;
  3715. end
  3716. else
  3717. s:=s+';';
  3718. if vo_is_hidden_para in hp.varoptions then
  3719. s:=s+'<';
  3720. case hp.varspez of
  3721. vs_var :
  3722. s:=s+'var ';
  3723. vs_const :
  3724. s:=s+'const ';
  3725. vs_out :
  3726. s:=s+'out ';
  3727. vs_constref :
  3728. s:=s+'constref ';
  3729. end;
  3730. if (pno_paranames in pno) then
  3731. s:=s+hp.realname+':';
  3732. if hp.univpara then
  3733. s:=s+'univ ';
  3734. if assigned(hp.vardef.typesym) then
  3735. begin
  3736. hs:=hp.vardef.typesym.realname;
  3737. if hs[1]<>'$' then
  3738. s:=s+hp.vardef.OwnerHierarchyName+hs
  3739. else
  3740. s:=s+hp.vardef.GetTypeName;
  3741. end
  3742. else
  3743. s:=s+hp.vardef.GetTypeName;
  3744. { default value }
  3745. if assigned(hp.defaultconstsym) then
  3746. begin
  3747. hpc:=tconstsym(hp.defaultconstsym);
  3748. hs:='';
  3749. case hpc.consttyp of
  3750. conststring,
  3751. constresourcestring :
  3752. begin
  3753. If hpc.value.len>0 then
  3754. begin
  3755. setLength(hs,hpc.value.len);
  3756. { don't write past the end of hs if the constant
  3757. is > 255 chars }
  3758. move(hpc.value.valueptr^,hs[1],length(hs));
  3759. { make sure that constant strings with newline chars
  3760. don't create a linebreak in the assembler code,
  3761. since comments are line-based. Also remove nulls
  3762. because the comments are written as a pchar. }
  3763. ReplaceCase(hs,#0,'.');
  3764. ReplaceCase(hs,#10,'.');
  3765. ReplaceCase(hs,#13,'.');
  3766. end;
  3767. end;
  3768. constreal :
  3769. str(pbestreal(hpc.value.valueptr)^,hs);
  3770. constpointer :
  3771. hs:=tostr(hpc.value.valueordptr);
  3772. constord :
  3773. begin
  3774. if is_boolean(hpc.constdef) then
  3775. begin
  3776. if hpc.value.valueord<>0 then
  3777. hs:='TRUE'
  3778. else
  3779. hs:='FALSE';
  3780. end
  3781. else
  3782. hs:=tostr(hpc.value.valueord);
  3783. end;
  3784. constnil :
  3785. hs:='nil';
  3786. constset :
  3787. hs:='<set>';
  3788. end;
  3789. if hs<>'' then
  3790. s:=s+'="'+hs+'"';
  3791. end;
  3792. if vo_is_hidden_para in hp.varoptions then
  3793. s:=s+'>';
  3794. end;
  3795. end;
  3796. if not first then
  3797. s:=s+')';
  3798. if (po_varargs in procoptions) then
  3799. s:=s+';VarArgs';
  3800. typename_paras:=s;
  3801. end;
  3802. function tabstractprocdef.is_methodpointer:boolean;
  3803. begin
  3804. result:=false;
  3805. end;
  3806. function tabstractprocdef.is_addressonly:boolean;
  3807. begin
  3808. result:=true;
  3809. end;
  3810. function tabstractprocdef.no_self_node: boolean;
  3811. begin
  3812. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  3813. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  3814. end;
  3815. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef;
  3816. var
  3817. j, nestinglevel: longint;
  3818. pvs, npvs: tparavarsym;
  3819. begin
  3820. nestinglevel:=parast.symtablelevel;
  3821. if newtyp=procdef then
  3822. begin
  3823. if (copytyp<>pc_bareproc) then
  3824. result:=tprocdef.create(nestinglevel)
  3825. else
  3826. result:=tprocdef.create(normal_function_level);
  3827. tprocdef(result).visibility:=vis_public;
  3828. end
  3829. else
  3830. begin
  3831. result:=tprocvardef.create(nestinglevel);
  3832. end;
  3833. tabstractprocdef(result).returndef:=returndef;
  3834. tabstractprocdef(result).returndefderef:=returndefderef;
  3835. pvs:=nil;
  3836. npvs:=nil;
  3837. for j:=0 to parast.symlist.count-1 do
  3838. begin
  3839. case tsym(parast.symlist[j]).typ of
  3840. paravarsym:
  3841. begin
  3842. pvs:=tparavarsym(parast.symlist[j]);
  3843. { in case of bare proc, don't copy self, vmt or framepointer
  3844. parameters }
  3845. if (copytyp=pc_bareproc) and
  3846. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result]*pvs.varoptions)<>[]) then
  3847. continue;
  3848. npvs:=tparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  3849. pvs.vardef,pvs.varoptions);
  3850. npvs.defaultconstsym:=pvs.defaultconstsym;
  3851. tabstractprocdef(result).parast.insert(npvs);
  3852. end;
  3853. constsym:
  3854. begin
  3855. // ignore, reuse original constym. Should also be duplicated
  3856. // be safe though
  3857. end;
  3858. symconst.typesym:
  3859. begin
  3860. // reuse original, part of generic declaration
  3861. end
  3862. else
  3863. internalerror(201160604);
  3864. end;
  3865. end;
  3866. tabstractprocdef(result).savesize:=savesize;
  3867. tabstractprocdef(result).proctypeoption:=proctypeoption;
  3868. tabstractprocdef(result).proccalloption:=proccalloption;
  3869. tabstractprocdef(result).procoptions:=procoptions;
  3870. if (copytyp=pc_bareproc) then
  3871. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  3872. if newtyp=procvardef then
  3873. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  3874. tabstractprocdef(result).callerargareasize:=callerargareasize;
  3875. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  3876. tabstractprocdef(result).maxparacount:=maxparacount;
  3877. tabstractprocdef(result).minparacount:=minparacount;
  3878. if po_explicitparaloc in procoptions then
  3879. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  3880. { recalculate parameter info }
  3881. tabstractprocdef(result).has_paraloc_info:=callnoside;
  3882. {$ifdef m68k}
  3883. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  3884. {$endif}
  3885. if (typ=procdef) and
  3886. (newtyp=procvardef) and
  3887. (owner.symtabletype=ObjectSymtable) then
  3888. include(tprocvardef(result).procoptions,po_methodpointer);
  3889. end;
  3890. procedure tabstractprocdef.check_mark_as_nested;
  3891. begin
  3892. { nested procvars require that nested functions use the Delphi-style
  3893. nested procedure calling convention }
  3894. if (parast.symtablelevel>normal_function_level) and
  3895. (m_nested_procvars in current_settings.modeswitches) then
  3896. include(procoptions,po_delphi_nested_cc);
  3897. end;
  3898. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  3899. begin
  3900. if (side in [callerside,callbothsides]) and
  3901. not(has_paraloc_info in [callerside,callbothsides]) then
  3902. begin
  3903. callerargareasize:=paramanager.create_paraloc_info(self,callerside);
  3904. if has_paraloc_info in [calleeside,callbothsides] then
  3905. has_paraloc_info:=callbothsides
  3906. else
  3907. has_paraloc_info:=callerside;
  3908. end;
  3909. if (side in [calleeside,callbothsides]) and
  3910. not(has_paraloc_info in [calleeside,callbothsides]) then
  3911. begin
  3912. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside);
  3913. if has_paraloc_info in [callerside,callbothsides] then
  3914. has_paraloc_info:=callbothsides
  3915. else
  3916. has_paraloc_info:=calleeside;
  3917. end;
  3918. end;
  3919. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  3920. var
  3921. p: tparavarsym;
  3922. ploc: PCGParalocation;
  3923. i: longint;
  3924. begin
  3925. result:=false;
  3926. init_paraloc_info(side);
  3927. for i:=0 to parast.SymList.Count-1 do
  3928. if tsym(parast.SymList[i]).typ=paravarsym then
  3929. begin
  3930. p:=tparavarsym(parast.SymList[i]);
  3931. { check if no parameter is located on the stack }
  3932. if is_open_array(p.vardef) or
  3933. is_array_of_const(p.vardef) then
  3934. begin
  3935. result:=true;
  3936. exit;
  3937. end;
  3938. ploc:=p.paraloc[side].location;
  3939. while assigned(ploc) do
  3940. begin
  3941. if (ploc^.loc=LOC_REFERENCE) then
  3942. begin
  3943. result:=true;
  3944. exit
  3945. end;
  3946. ploc:=ploc^.next;
  3947. end;
  3948. end;
  3949. end;
  3950. function tabstractprocdef.is_pushleftright: boolean;
  3951. begin
  3952. {$if defined(i8086) or defined(i386)}
  3953. result:=proccalloption in pushleftright_pocalls;
  3954. {$else}
  3955. result:=false;
  3956. {$endif}
  3957. end;
  3958. function tabstractprocdef.address_size: asizeint;
  3959. begin
  3960. {$ifdef i8086}
  3961. if po_far in procoptions then
  3962. result:=sizeof(pint)+2
  3963. else
  3964. {$endif i8086}
  3965. result:=sizeof(pint);
  3966. end;
  3967. {***************************************************************************
  3968. TPROCDEF
  3969. ***************************************************************************}
  3970. function tprocdef.GetResultName: PShortString;
  3971. begin
  3972. if not assigned(implprocdefinfo) then
  3973. internalerror(2014010301);
  3974. result:=implprocdefinfo^.resultname;
  3975. end;
  3976. procedure tprocdef.SetResultName(AValue: PShortString);
  3977. begin
  3978. if not assigned(implprocdefinfo) then
  3979. internalerror(2014010302);
  3980. implprocdefinfo^.resultname:=AValue;
  3981. end;
  3982. function tprocdef.GetParentFPInitBlock: tnode;
  3983. begin
  3984. if not assigned(implprocdefinfo) then
  3985. internalerror(2014010303);
  3986. result:=implprocdefinfo^.parentfpinitblock;
  3987. end;
  3988. function tprocdef.GetParentFPStruct: tsym;
  3989. begin
  3990. if not assigned(implprocdefinfo) then
  3991. internalerror(2014010304);
  3992. result:=implprocdefinfo^.parentfpstruct;
  3993. end;
  3994. function tprocdef.GetParentFPStructPtrType: tdef;
  3995. begin
  3996. if not assigned(implprocdefinfo) then
  3997. internalerror(2014010305);
  3998. result:=implprocdefinfo^.parentfpstructptrtype;
  3999. end;
  4000. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  4001. begin
  4002. if not assigned(implprocdefinfo) then
  4003. internalerror(2014010306);
  4004. implprocdefinfo^.parentfpinitblock:=AValue;
  4005. end;
  4006. function tprocdef.Getprocendtai: tai;
  4007. begin
  4008. if not assigned(implprocdefinfo) then
  4009. internalerror(2014010307);
  4010. result:=implprocdefinfo^.procendtai;
  4011. end;
  4012. function tprocdef.Getprocstarttai: tai;
  4013. begin
  4014. if not assigned(implprocdefinfo) then
  4015. internalerror(2014010308);
  4016. result:=implprocdefinfo^.procstarttai;
  4017. end;
  4018. procedure tprocdef.Setprocendtai(AValue: tai);
  4019. begin
  4020. if not assigned(implprocdefinfo) then
  4021. internalerror(2014010309);
  4022. implprocdefinfo^.procendtai:=AValue;
  4023. end;
  4024. function tprocdef.Getskpara: pointer;
  4025. begin
  4026. if not assigned(implprocdefinfo) then
  4027. internalerror(2014010310);
  4028. result:=implprocdefinfo^.skpara;
  4029. end;
  4030. procedure tprocdef.Setskpara(AValue: pointer);
  4031. begin
  4032. if not assigned(implprocdefinfo) then
  4033. internalerror(2014010311);
  4034. implprocdefinfo^.skpara:=AValue;
  4035. end;
  4036. function tprocdef.Getforwarddef: boolean;
  4037. begin
  4038. if not assigned(implprocdefinfo) then
  4039. internalerror(2014010312);
  4040. result:=implprocdefinfo^.forwarddef;
  4041. end;
  4042. function tprocdef.Gethasforward: boolean;
  4043. begin
  4044. if not assigned(implprocdefinfo) then
  4045. internalerror(2014010313);
  4046. result:=implprocdefinfo^.hasforward;
  4047. end;
  4048. function tprocdef.Getinterfacedef: boolean;
  4049. begin
  4050. if not assigned(implprocdefinfo) then
  4051. internalerror(2014010314);
  4052. result:=implprocdefinfo^.interfacedef;
  4053. end;
  4054. procedure tprocdef.Setforwarddef(AValue: boolean);
  4055. begin
  4056. if not assigned(implprocdefinfo) then
  4057. internalerror(2014010315);
  4058. implprocdefinfo^.forwarddef:=AValue;
  4059. end;
  4060. procedure tprocdef.Sethasforward(AValue: boolean);
  4061. begin
  4062. if not assigned(implprocdefinfo) then
  4063. internalerror(2014010316);
  4064. implprocdefinfo^.hasforward:=AValue;
  4065. end;
  4066. procedure tprocdef.Setinterfacedef(AValue: boolean);
  4067. begin
  4068. if not assigned(implprocdefinfo) then
  4069. internalerror(2014010317);
  4070. implprocdefinfo^.interfacedef:=AValue;
  4071. end;
  4072. procedure tprocdef.Setprocstarttai(AValue: tai);
  4073. begin
  4074. if not assigned(implprocdefinfo) then
  4075. internalerror(2014010318);
  4076. implprocdefinfo^.procstarttai:=AValue;
  4077. end;
  4078. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  4079. begin
  4080. if not assigned(implprocdefinfo) then
  4081. internalerror(2014010319);
  4082. implprocdefinfo^.parentfpstruct:=AValue;
  4083. end;
  4084. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  4085. begin
  4086. if not assigned(implprocdefinfo) then
  4087. internalerror(2014010320);
  4088. implprocdefinfo^.parentfpstructptrtype:=AValue;
  4089. end;
  4090. constructor tprocdef.create(level:byte);
  4091. begin
  4092. inherited create(procdef,level);
  4093. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  4094. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  4095. {$ifdef symansistr}
  4096. _mangledname:='';
  4097. {$else symansistr}
  4098. _mangledname:=nil;
  4099. {$endif symansistr}
  4100. fileinfo:=current_filepos;
  4101. extnumber:=$ffff;
  4102. aliasnames:=TCmdStrList.create;
  4103. funcretsym:=nil;
  4104. forwarddef:=true;
  4105. interfacedef:=false;
  4106. hasforward:=false;
  4107. struct := nil;
  4108. import_dll:=nil;
  4109. import_name:=nil;
  4110. import_nr:=0;
  4111. inlininginfo:=nil;
  4112. deprecatedmsg:=nil;
  4113. {$if defined(i386) or defined(i8086)}
  4114. fpu_used:=maxfpuregs;
  4115. {$endif i386 or i8086}
  4116. end;
  4117. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  4118. var
  4119. i,aliasnamescount : longint;
  4120. level : byte;
  4121. begin
  4122. inherited ppuload(procdef,ppufile);
  4123. {$ifdef symansistr}
  4124. if po_has_mangledname in procoptions then
  4125. _mangledname:=ppufile.getansistring
  4126. else
  4127. _mangledname:='';
  4128. {$else symansistr}
  4129. if po_has_mangledname in procoptions then
  4130. _mangledname:=stringdup(ppufile.getstring)
  4131. else
  4132. _mangledname:=nil;
  4133. {$endif symansistr}
  4134. extnumber:=ppufile.getword;
  4135. level:=ppufile.getbyte;
  4136. ppufile.getderef(structderef);
  4137. ppufile.getderef(procsymderef);
  4138. ppufile.getposinfo(fileinfo);
  4139. visibility:=tvisibility(ppufile.getbyte);
  4140. ppufile.getsmallset(symoptions);
  4141. if sp_has_deprecated_msg in symoptions then
  4142. deprecatedmsg:=stringdup(ppufile.getstring)
  4143. else
  4144. deprecatedmsg:=nil;
  4145. synthetickind:=tsynthetickind(ppufile.getbyte);
  4146. {$ifdef powerpc}
  4147. { library symbol for AmigaOS/MorphOS }
  4148. ppufile.getderef(libsymderef);
  4149. {$endif powerpc}
  4150. { import stuff }
  4151. if po_has_importdll in procoptions then
  4152. import_dll:=stringdup(ppufile.getstring)
  4153. else
  4154. import_dll:=nil;
  4155. if po_has_importname in procoptions then
  4156. import_name:=stringdup(ppufile.getstring)
  4157. else
  4158. import_name:=nil;
  4159. import_nr:=ppufile.getword;
  4160. if (po_msgint in procoptions) then
  4161. messageinf.i:=ppufile.getlongint;
  4162. if (po_msgstr in procoptions) then
  4163. messageinf.str:=stringdup(ppufile.getstring);
  4164. if (po_dispid in procoptions) then
  4165. dispid:=ppufile.getlongint;
  4166. { inline stuff }
  4167. if (po_has_inlininginfo in procoptions) then
  4168. begin
  4169. ppufile.getderef(funcretsymderef);
  4170. new(inlininginfo);
  4171. ppufile.getsmallset(inlininginfo^.flags);
  4172. end
  4173. else
  4174. begin
  4175. inlininginfo:=nil;
  4176. funcretsym:=nil;
  4177. end;
  4178. aliasnames:=TCmdStrList.create;
  4179. { count alias names }
  4180. aliasnamescount:=ppufile.getbyte;
  4181. for i:=1 to aliasnamescount do
  4182. aliasnames.insert(ppufile.getstring);
  4183. isempty:=ppufile.getbyte<>0;
  4184. { load para symtable }
  4185. parast:=tparasymtable.create(self,level);
  4186. tparasymtable(parast).ppuload(ppufile);
  4187. { load local symtable }
  4188. if (po_has_inlininginfo in procoptions) then
  4189. begin
  4190. localst:=tlocalsymtable.create(self,level);
  4191. tlocalsymtable(localst).ppuload(ppufile);
  4192. end
  4193. else
  4194. localst:=nil;
  4195. { inline stuff }
  4196. if (po_has_inlininginfo in procoptions) then
  4197. inlininginfo^.code:=ppuloadnodetree(ppufile);
  4198. { default values for no persistent data }
  4199. if (cs_link_deffile in current_settings.globalswitches) and
  4200. (tf_need_export in target_info.flags) and
  4201. (po_exports in procoptions) then
  4202. deffile.AddExport(mangledname);
  4203. { Disable po_has_inlining until the derefimpl is done }
  4204. exclude(procoptions,po_has_inlininginfo);
  4205. {$ifdef i386}
  4206. fpu_used:=maxfpuregs;
  4207. {$endif i386}
  4208. end;
  4209. destructor tprocdef.destroy;
  4210. begin
  4211. aliasnames.free;
  4212. aliasnames:=nil;
  4213. if assigned(localst) and
  4214. (localst.symtabletype<>staticsymtable) then
  4215. begin
  4216. {$ifdef MEMDEBUG}
  4217. memproclocalst.start;
  4218. {$endif MEMDEBUG}
  4219. localst.free;
  4220. localst:=nil;
  4221. {$ifdef MEMDEBUG}
  4222. memproclocalst.start;
  4223. {$endif MEMDEBUG}
  4224. end;
  4225. if assigned(inlininginfo) then
  4226. begin
  4227. {$ifdef MEMDEBUG}
  4228. memprocnodetree.start;
  4229. {$endif MEMDEBUG}
  4230. tnode(inlininginfo^.code).free;
  4231. {$ifdef MEMDEBUG}
  4232. memprocnodetree.start;
  4233. {$endif MEMDEBUG}
  4234. dispose(inlininginfo);
  4235. inlininginfo:=nil;
  4236. end;
  4237. {$ifdef jvm}
  4238. exprasmlist.free;
  4239. {$endif}
  4240. if assigned(implprocdefinfo) then
  4241. begin
  4242. stringdispose(implprocdefinfo^.resultname);
  4243. freemem(implprocdefinfo);
  4244. implprocdefinfo:=nil;
  4245. end;
  4246. stringdispose(import_dll);
  4247. stringdispose(import_name);
  4248. stringdispose(deprecatedmsg);
  4249. if (po_msgstr in procoptions) then
  4250. stringdispose(messageinf.str);
  4251. {$ifndef symansistr}
  4252. if assigned(_mangledname) then
  4253. begin
  4254. {$ifdef MEMDEBUG}
  4255. memmanglednames.start;
  4256. {$endif MEMDEBUG}
  4257. stringdispose(_mangledname);
  4258. {$ifdef MEMDEBUG}
  4259. memmanglednames.stop;
  4260. {$endif MEMDEBUG}
  4261. end;
  4262. {$endif symansistr}
  4263. inherited destroy;
  4264. end;
  4265. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  4266. var
  4267. oldintfcrc : boolean;
  4268. aliasnamescount : longint;
  4269. item : TCmdStrListItem;
  4270. begin
  4271. { released procdef? }
  4272. if not assigned(parast) then
  4273. exit;
  4274. inherited ppuwrite(ppufile);
  4275. {$ifdef symansistr}
  4276. if po_has_mangledname in procoptions then
  4277. ppufile.putansistring(_mangledname);
  4278. {$else symansistr}
  4279. if po_has_mangledname in procoptions then
  4280. ppufile.putstring(_mangledname^);
  4281. {$endif symansistr}
  4282. ppufile.putword(extnumber);
  4283. ppufile.putbyte(parast.symtablelevel);
  4284. ppufile.putderef(structderef);
  4285. ppufile.putderef(procsymderef);
  4286. ppufile.putposinfo(fileinfo);
  4287. ppufile.putbyte(byte(visibility));
  4288. ppufile.putsmallset(symoptions);
  4289. if sp_has_deprecated_msg in symoptions then
  4290. ppufile.putstring(deprecatedmsg^);
  4291. ppufile.putbyte(byte(synthetickind));
  4292. {$ifdef powerpc}
  4293. { library symbol for AmigaOS/MorphOS }
  4294. ppufile.putderef(libsymderef);
  4295. {$endif powerpc}
  4296. { import }
  4297. if po_has_importdll in procoptions then
  4298. ppufile.putstring(import_dll^);
  4299. if po_has_importname in procoptions then
  4300. ppufile.putstring(import_name^);
  4301. ppufile.putword(import_nr);
  4302. if (po_msgint in procoptions) then
  4303. ppufile.putlongint(messageinf.i);
  4304. if (po_msgstr in procoptions) then
  4305. ppufile.putstring(messageinf.str^);
  4306. if (po_dispid in procoptions) then
  4307. ppufile.putlongint(dispid);
  4308. { inline stuff }
  4309. oldintfcrc:=ppufile.do_crc;
  4310. ppufile.do_crc:=false;
  4311. if (po_has_inlininginfo in procoptions) then
  4312. begin
  4313. ppufile.putderef(funcretsymderef);
  4314. ppufile.putsmallset(inlininginfo^.flags);
  4315. end;
  4316. { count alias names }
  4317. aliasnamescount:=0;
  4318. item:=TCmdStrListItem(aliasnames.first);
  4319. while assigned(item) do
  4320. begin
  4321. inc(aliasnamescount);
  4322. item:=TCmdStrListItem(item.next);
  4323. end;
  4324. if aliasnamescount>255 then
  4325. internalerror(200711021);
  4326. ppufile.putbyte(aliasnamescount);
  4327. item:=TCmdStrListItem(aliasnames.first);
  4328. while assigned(item) do
  4329. begin
  4330. ppufile.putstring(item.str);
  4331. item:=TCmdStrListItem(item.next);
  4332. end;
  4333. ppufile.putbyte(ord(isempty));
  4334. ppufile.do_crc:=oldintfcrc;
  4335. { write this entry }
  4336. ppufile.writeentry(ibprocdef);
  4337. { Save the para symtable, this is taken from the interface }
  4338. tparasymtable(parast).ppuwrite(ppufile);
  4339. { save localsymtable for inline procedures or when local
  4340. browser info is requested, this has no influence on the crc }
  4341. if (po_has_inlininginfo in procoptions) then
  4342. begin
  4343. oldintfcrc:=ppufile.do_crc;
  4344. ppufile.do_crc:=false;
  4345. tlocalsymtable(localst).ppuwrite(ppufile);
  4346. ppufile.do_crc:=oldintfcrc;
  4347. end;
  4348. { node tree for inlining }
  4349. oldintfcrc:=ppufile.do_crc;
  4350. ppufile.do_crc:=false;
  4351. if (po_has_inlininginfo in procoptions) then
  4352. ppuwritenodetree(ppufile,inlininginfo^.code);
  4353. ppufile.do_crc:=oldintfcrc;
  4354. end;
  4355. function tprocdef.fullprocname(showhidden:boolean):string;
  4356. var
  4357. pno: tprocnameoptions;
  4358. begin
  4359. pno:=[];
  4360. if showhidden then
  4361. include(pno,pno_showhidden);
  4362. result:=customprocname(pno);
  4363. end;
  4364. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  4365. var
  4366. s, rn : ansistring;
  4367. t : ttoken;
  4368. begin
  4369. {$ifdef EXTDEBUG}
  4370. include(pno,pno_showhidden);
  4371. {$endif EXTDEBUG}
  4372. s:='';
  4373. if proctypeoption=potype_operator then
  4374. begin
  4375. for t:=NOTOKEN to last_overloaded do
  4376. if procsym.realname='$'+overloaded_names[t] then
  4377. begin
  4378. s:='operator ';
  4379. if (pno_ownername in pno) and
  4380. assigned(struct) then
  4381. s:=s+struct.RttiName+'.';
  4382. s:=s+arraytokeninfo[t].str+typename_paras(pno);
  4383. break;
  4384. end;
  4385. end
  4386. else
  4387. begin
  4388. if (po_classmethod in procoptions) and
  4389. not(pno_noclassmarker in pno) then
  4390. s:='class ';
  4391. case proctypeoption of
  4392. potype_constructor,
  4393. potype_class_constructor:
  4394. s:=s+'constructor ';
  4395. potype_class_destructor,
  4396. potype_destructor:
  4397. s:=s+'destructor ';
  4398. else
  4399. if (pno_proctypeoption in pno) then
  4400. begin
  4401. if assigned(returndef) and
  4402. not(is_void(returndef)) then
  4403. s:=s+'function '
  4404. else
  4405. s:=s+'procedure ';
  4406. end;
  4407. end;
  4408. if (pno_ownername in pno) and
  4409. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  4410. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  4411. rn:=procsym.realname;
  4412. if (pno_noleadingdollar in pno) and
  4413. (rn[1]='$') then
  4414. delete(rn,1,1);
  4415. s:=s+rn+typename_paras(pno);
  4416. end;
  4417. if not(proctypeoption in [potype_constructor,potype_destructor,
  4418. potype_class_constructor,potype_class_destructor]) and
  4419. assigned(returndef) and
  4420. not(is_void(returndef)) then
  4421. s:=s+':'+returndef.GetTypeName;
  4422. if owner.symtabletype=localsymtable then
  4423. s:=s+' is nested';
  4424. s:=s+';';
  4425. { forced calling convention? }
  4426. if (po_hascallingconvention in procoptions) then
  4427. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  4428. if (po_staticmethod in procoptions) and
  4429. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  4430. s:=s+' Static;';
  4431. customprocname:=s;
  4432. end;
  4433. function tprocdef.is_methodpointer:boolean;
  4434. begin
  4435. { don't check assigned(_class), that's also the case for nested
  4436. procedures inside methods }
  4437. result:=(owner.symtabletype=ObjectSymtable)and not no_self_node;
  4438. end;
  4439. function tprocdef.is_addressonly:boolean;
  4440. begin
  4441. result:=assigned(owner) and
  4442. not is_methodpointer and
  4443. (not(m_nested_procvars in current_settings.modeswitches) or
  4444. not is_nested_pd(self));
  4445. end;
  4446. procedure tprocdef.make_external;
  4447. begin
  4448. include(procoptions,po_external);
  4449. forwarddef:=false;
  4450. end;
  4451. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  4452. begin
  4453. case t of
  4454. gs_local :
  4455. GetSymtable:=localst;
  4456. gs_para :
  4457. GetSymtable:=parast;
  4458. else
  4459. GetSymtable:=nil;
  4460. end;
  4461. end;
  4462. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp): tstoreddef;
  4463. var
  4464. j : longint;
  4465. begin
  4466. result:=inherited getcopyas(newtyp,copytyp);
  4467. if newtyp=procvardef then
  4468. exit;
  4469. { don't copy mangled name, can be different }
  4470. tprocdef(result).messageinf:=messageinf;
  4471. tprocdef(result).dispid:=dispid;
  4472. if po_msgstr in procoptions then
  4473. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  4474. tprocdef(result).symoptions:=symoptions;
  4475. if assigned(deprecatedmsg) then
  4476. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  4477. { will have to be associated with appropriate procsym }
  4478. tprocdef(result).procsym:=nil;
  4479. if copytyp<>pc_bareproc then
  4480. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  4481. if assigned(funcretsym) then
  4482. begin
  4483. if funcretsym.owner=parast then
  4484. begin
  4485. j:=parast.symlist.indexof(funcretsym);
  4486. if j<0 then
  4487. internalerror(2011040606);
  4488. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  4489. end
  4490. else if funcretsym.owner=localst then
  4491. begin
  4492. { nothing to do, will be inserted for the new procdef while
  4493. parsing its body (by pdecsub.insert_funcret_local) }
  4494. end
  4495. else
  4496. internalerror(2011040605);
  4497. end;
  4498. { will have to be associated with a new struct }
  4499. tprocdef(result).struct:=nil;
  4500. {$if defined(powerpc) or defined(m68k)}
  4501. tprocdef(result).libsym:=libsym;
  4502. {$endif powerpc or m68k}
  4503. if assigned(implprocdefinfo) then
  4504. begin
  4505. if assigned(resultname) then
  4506. tprocdef(result).resultname:=stringdup(resultname^);
  4507. end;
  4508. if assigned(import_dll) then
  4509. tprocdef(result).import_dll:=stringdup(import_dll^);
  4510. if assigned(import_name) then
  4511. tprocdef(result).import_name:=stringdup(import_name^);
  4512. tprocdef(result).import_nr:=import_nr;
  4513. tprocdef(result).extnumber:=$ffff;
  4514. {$if defined(i386) or defined(i8086)}
  4515. tprocdef(result).fpu_used:=fpu_used;
  4516. {$endif i386 or i8086}
  4517. tprocdef(result).visibility:=visibility;
  4518. tprocdef(result).synthetickind:=synthetickind;
  4519. { we need a separate implementation for the copied def }
  4520. tprocdef(result).forwarddef:=true;
  4521. tprocdef(result).interfacedef:=true;
  4522. { create new paralist }
  4523. tprocdef(result).calcparas;
  4524. end;
  4525. function tprocdef.getcopy: tstoreddef;
  4526. begin
  4527. result:=getcopyas(procdef,pc_normal);
  4528. end;
  4529. procedure tprocdef.buildderef;
  4530. begin
  4531. inherited buildderef;
  4532. structderef.build(struct);
  4533. { procsym that originaly defined this definition, should be in the
  4534. same symtable }
  4535. procsymderef.build(procsym);
  4536. {$ifdef powerpc}
  4537. { library symbol for AmigaOS/MorphOS }
  4538. libsymderef.build(libsym);
  4539. {$endif powerpc}
  4540. end;
  4541. procedure tprocdef.buildderefimpl;
  4542. begin
  4543. inherited buildderefimpl;
  4544. { inline tree }
  4545. if (po_has_inlininginfo in procoptions) then
  4546. begin
  4547. { Localst is not available for main/unit init }
  4548. if assigned(localst) then
  4549. begin
  4550. tlocalsymtable(localst).buildderef;
  4551. tlocalsymtable(localst).buildderefimpl;
  4552. end;
  4553. funcretsymderef.build(funcretsym);
  4554. inlininginfo^.code.buildderefimpl;
  4555. end;
  4556. end;
  4557. procedure tprocdef.deref;
  4558. begin
  4559. inherited deref;
  4560. struct:=tabstractrecorddef(structderef.resolve);
  4561. { procsym that originaly defined this definition, should be in the
  4562. same symtable }
  4563. procsym:=tprocsym(procsymderef.resolve);
  4564. {$ifdef powerpc}
  4565. { library symbol for AmigaOS/MorphOS }
  4566. libsym:=tsym(libsymderef.resolve);
  4567. {$endif powerpc}
  4568. end;
  4569. procedure tprocdef.derefimpl;
  4570. begin
  4571. { Enable has_inlininginfo when the inlininginfo
  4572. structure is available. The has_inlininginfo was disabled
  4573. after the load, since the data was invalid }
  4574. if assigned(inlininginfo) then
  4575. include(procoptions,po_has_inlininginfo);
  4576. { Locals }
  4577. if assigned(localst) then
  4578. begin
  4579. tlocalsymtable(localst).deref;
  4580. tlocalsymtable(localst).derefimpl;
  4581. end;
  4582. { Inline }
  4583. if (po_has_inlininginfo in procoptions) then
  4584. begin
  4585. inlininginfo^.code.derefimpl;
  4586. { funcretsym, this is always located in the localst }
  4587. funcretsym:=tsym(funcretsymderef.resolve);
  4588. end
  4589. else
  4590. begin
  4591. { safety }
  4592. { Not safe! A unit may be reresolved after its interface has been
  4593. parsed but before its implementation has been parsed, and in that
  4594. case the funcretsym is still required!
  4595. funcretsym:=nil; }
  4596. end;
  4597. end;
  4598. function tprocdef.GetTypeName : string;
  4599. begin
  4600. GetTypeName := FullProcName(false);
  4601. end;
  4602. function tprocdef.mangledname : TSymStr;
  4603. begin
  4604. {$ifdef symansistr}
  4605. if _mangledname<>'' then
  4606. {$else symansistr}
  4607. if assigned(_mangledname) then
  4608. {$endif symansistr}
  4609. begin
  4610. {$ifdef compress}
  4611. {$error add support for ansistrings in case of symansistr}
  4612. mangledname:=minilzw_decode(_mangledname^);
  4613. {$else}
  4614. {$ifdef symansistr}
  4615. mangledname:=_mangledname;
  4616. {$else symansistr}
  4617. mangledname:=_mangledname^;
  4618. {$endif symansistr}
  4619. {$endif}
  4620. exit;
  4621. end;
  4622. {$ifndef jvm}
  4623. mangledname:=defaultmangledname;
  4624. {$else not jvm}
  4625. mangledname:=jvmmangledbasename(false);
  4626. if (po_has_importdll in procoptions) then
  4627. begin
  4628. { import_dll comes from "external 'import_dll_name' name 'external_name'" }
  4629. if assigned(import_dll) then
  4630. mangledname:=import_dll^+'/'+mangledname
  4631. else
  4632. internalerror(2010122607);
  4633. end
  4634. else
  4635. jvmaddtypeownerprefix(owner,mangledname);
  4636. {$endif not jvm}
  4637. {$ifdef compress}
  4638. {$error add support for ansistrings in case of symansistr}
  4639. _mangledname:=stringdup(minilzw_encode(mangledname));
  4640. {$else}
  4641. {$ifdef symansistr}
  4642. _mangledname:=mangledname;
  4643. {$else symansistr}
  4644. _mangledname:=stringdup(mangledname);
  4645. {$endif symansistr}
  4646. {$endif}
  4647. end;
  4648. function tprocdef.defaultmangledname: TSymStr;
  4649. var
  4650. hp : TParavarsym;
  4651. hs : TSymStr;
  4652. crc : dword;
  4653. newlen,
  4654. oldlen,
  4655. i : integer;
  4656. begin
  4657. hp:=nil;
  4658. { we need to use the symtable where the procsym is inserted,
  4659. because that is visible to the world }
  4660. defaultmangledname:=make_mangledname('',procsym.owner,procsym.name);
  4661. oldlen:=length(defaultmangledname);
  4662. { add parameter types }
  4663. for i:=0 to paras.count-1 do
  4664. begin
  4665. hp:=tparavarsym(paras[i]);
  4666. if not(vo_is_hidden_para in hp.varoptions) then
  4667. defaultmangledname:=defaultmangledname+'$'+hp.vardef.mangledparaname;
  4668. end;
  4669. { add resultdef, add $$ as separator to make it unique from a
  4670. parameter separator }
  4671. if not is_void(returndef) then
  4672. defaultmangledname:=defaultmangledname+'$$'+returndef.mangledparaname;
  4673. newlen:=length(defaultmangledname);
  4674. { Replace with CRC if the parameter line is very long }
  4675. if (newlen-oldlen>12) and
  4676. ((newlen>100) or (newlen-oldlen>64)) then
  4677. begin
  4678. crc:=0;
  4679. for i:=0 to paras.count-1 do
  4680. begin
  4681. hp:=tparavarsym(paras[i]);
  4682. if not(vo_is_hidden_para in hp.varoptions) then
  4683. begin
  4684. hs:=hp.vardef.mangledparaname;
  4685. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4686. end;
  4687. end;
  4688. hs:=hp.vardef.mangledparaname;
  4689. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4690. defaultmangledname:=Copy(defaultmangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  4691. end;
  4692. end;
  4693. function tprocdef.cplusplusmangledname : TSymStr;
  4694. function getcppparaname(p : tdef) : TSymStr;
  4695. const
  4696. {$ifdef NAMEMANGLING_GCC2}
  4697. ordtype2str : array[tordtype] of string[2] = (
  4698. '',
  4699. 'Uc','Us','Ui','Us',
  4700. 'Sc','s','i','x',
  4701. 'b','b','b','b','b',
  4702. 'c','w','x');
  4703. {$else NAMEMANGLING_GCC2}
  4704. ordtype2str : array[tordtype] of string[1] = (
  4705. 'v',
  4706. 'h','t','j','y',
  4707. 'a','s','i','x',
  4708. 'b','b','b','b',
  4709. 'b','b','b','b',
  4710. 'c','w','x');
  4711. floattype2str : array[tfloattype] of string[1] = (
  4712. 'f','d','e','e',
  4713. 'd','d','g');
  4714. {$endif NAMEMANGLING_GCC2}
  4715. var
  4716. s : TSymStr;
  4717. begin
  4718. case p.typ of
  4719. orddef:
  4720. s:=ordtype2str[torddef(p).ordtype];
  4721. pointerdef:
  4722. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  4723. {$ifndef NAMEMANGLING_GCC2}
  4724. floatdef:
  4725. s:=floattype2str[tfloatdef(p).floattype];
  4726. {$endif NAMEMANGLING_GCC2}
  4727. else
  4728. internalerror(2103001);
  4729. end;
  4730. getcppparaname:=s;
  4731. end;
  4732. var
  4733. s,s2 : TSymStr;
  4734. hp : TParavarsym;
  4735. i : integer;
  4736. begin
  4737. {$ifdef NAMEMANGLING_GCC2}
  4738. { outdated gcc 2.x name mangling scheme }
  4739. s := procsym.realname;
  4740. if procsym.owner.symtabletype=ObjectSymtable then
  4741. begin
  4742. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  4743. case proctypeoption of
  4744. potype_destructor:
  4745. s:='_$_'+tostr(length(s2))+s2;
  4746. potype_constructor:
  4747. s:='___'+tostr(length(s2))+s2;
  4748. else
  4749. s:='_'+s+'__'+tostr(length(s2))+s2;
  4750. end;
  4751. end
  4752. else s:=s+'__';
  4753. s:=s+'F';
  4754. { concat modifiers }
  4755. { !!!!! }
  4756. { now we handle the parameters }
  4757. if maxparacount>0 then
  4758. begin
  4759. for i:=0 to paras.count-1 do
  4760. begin
  4761. hp:=tparavarsym(paras[i]);
  4762. { no hidden parameters form part of a C++ mangled name:
  4763. a) self is not included
  4764. b) there are no "high" or other hidden parameters
  4765. }
  4766. if vo_is_hidden_para in hp.varoptions then
  4767. continue;
  4768. s2:=getcppparaname(hp.vardef);
  4769. if hp.varspez in [vs_var,vs_out] then
  4770. s2:='R'+s2;
  4771. s:=s+s2;
  4772. end;
  4773. end
  4774. else
  4775. s:=s+'v';
  4776. cplusplusmangledname:=s;
  4777. {$else NAMEMANGLING_GCC2}
  4778. { gcc 3.x and 4.x name mangling scheme }
  4779. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  4780. if procsym.owner.symtabletype=ObjectSymtable then
  4781. begin
  4782. s:='_ZN';
  4783. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  4784. s:=s+tostr(length(s2))+s2;
  4785. case proctypeoption of
  4786. potype_constructor:
  4787. s:=s+'C1';
  4788. potype_destructor:
  4789. s:=s+'D1';
  4790. else
  4791. s:=s+tostr(length(procsym.realname))+procsym.realname;
  4792. end;
  4793. s:=s+'E';
  4794. end
  4795. else
  4796. s:=procsym.realname;
  4797. { now we handle the parameters }
  4798. if maxparacount>0 then
  4799. begin
  4800. for i:=0 to paras.count-1 do
  4801. begin
  4802. hp:=tparavarsym(paras[i]);
  4803. { no hidden parameters form part of a C++ mangled name:
  4804. a) self is not included
  4805. b) there are no "high" or other hidden parameters
  4806. }
  4807. if vo_is_hidden_para in hp.varoptions then
  4808. continue;
  4809. s2:=getcppparaname(hp.vardef);
  4810. if hp.varspez in [vs_var,vs_out] then
  4811. s2:='R'+s2;
  4812. s:=s+s2;
  4813. end;
  4814. end
  4815. else
  4816. s:=s+'v';
  4817. cplusplusmangledname:=s;
  4818. {$endif NAMEMANGLING_GCC2}
  4819. end;
  4820. function tprocdef.objcmangledname : TSymStr;
  4821. var
  4822. manglednamelen: longint;
  4823. iscatmethod : boolean;
  4824. begin
  4825. if not (po_msgstr in procoptions) then
  4826. internalerror(2009030901);
  4827. { we may very well need longer strings to handle these... }
  4828. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  4829. length('+"[ ]"')+length(messageinf.str^);
  4830. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  4831. if (iscatmethod) then
  4832. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  4833. if manglednamelen>255 then
  4834. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  4835. if not(po_classmethod in procoptions) then
  4836. result:='"-['
  4837. else
  4838. result:='"+[';
  4839. { quotes are necessary because the +/- otherwise confuse the assembler
  4840. into expecting a number
  4841. }
  4842. if iscatmethod then
  4843. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  4844. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  4845. if iscatmethod then
  4846. result:=result+')';
  4847. result:=result+' '+messageinf.str^+']"';
  4848. end;
  4849. {$ifdef jvm}
  4850. function tprocdef.jvmmangledbasename(signature: boolean): TSymStr;
  4851. var
  4852. vs: tparavarsym;
  4853. i: longint;
  4854. founderror: tdef;
  4855. tmpresult: TSymStr;
  4856. container: tsymtable;
  4857. begin
  4858. { format:
  4859. * method definition (in Jasmin):
  4860. (private|protected|public) [static] method(parametertypes)returntype
  4861. * method invocation
  4862. package/class/method(parametertypes)returntype
  4863. -> store common part: method(parametertypes)returntype and
  4864. adorn as required when using it.
  4865. }
  4866. if not signature then
  4867. begin
  4868. { method name }
  4869. { special names for constructors and class constructors }
  4870. if proctypeoption=potype_constructor then
  4871. tmpresult:='<init>'
  4872. else if proctypeoption in [potype_class_constructor,potype_unitinit] then
  4873. tmpresult:='<clinit>'
  4874. else if po_has_importname in procoptions then
  4875. begin
  4876. if assigned(import_name) then
  4877. tmpresult:=import_name^
  4878. else
  4879. internalerror(2010122608);
  4880. end
  4881. else
  4882. begin
  4883. tmpresult:=procsym.realname;
  4884. if tmpresult[1]='$' then
  4885. tmpresult:=copy(tmpresult,2,length(tmpresult)-1);
  4886. { nested functions }
  4887. container:=owner;
  4888. while container.symtabletype=localsymtable do
  4889. begin
  4890. tmpresult:='$'+tprocdef(owner.defowner).procsym.realname+'$'+tostr(tprocdef(owner.defowner).procsym.symid)+'$'+tmpresult;
  4891. container:=container.defowner.owner;
  4892. end;
  4893. end;
  4894. end
  4895. else
  4896. tmpresult:='';
  4897. { parameter types }
  4898. tmpresult:=tmpresult+'(';
  4899. { not the case for the main program (not required for defaultmangledname
  4900. because setmangledname() is called for the main program; in case of
  4901. the JVM, this only sets the importname, however) }
  4902. if assigned(paras) then
  4903. begin
  4904. init_paraloc_info(callerside);
  4905. for i:=0 to paras.count-1 do
  4906. begin
  4907. vs:=tparavarsym(paras[i]);
  4908. { function result is not part of the mangled name }
  4909. if vo_is_funcret in vs.varoptions then
  4910. continue;
  4911. { self pointer neither, except for class methods (the JVM only
  4912. supports static class methods natively, so the self pointer
  4913. here is a regular parameter as far as the JVM is concerned }
  4914. if not(po_classmethod in procoptions) and
  4915. (vo_is_self in vs.varoptions) then
  4916. continue;
  4917. { passing by reference is emulated by passing an array of one
  4918. element containing the value; for types that aren't pointers
  4919. in regular Pascal, simply passing the underlying pointer type
  4920. does achieve regular call-by-reference semantics though;
  4921. formaldefs always have to be passed like that because their
  4922. contents can be replaced }
  4923. if paramanager.push_copyout_param(vs.varspez,vs.vardef,proccalloption) then
  4924. tmpresult:=tmpresult+'[';
  4925. { Add the parameter type. }
  4926. if not jvmaddencodedtype(vs.vardef,false,tmpresult,signature,founderror) then
  4927. { an internalerror here is also triggered in case of errors in the source code }
  4928. tmpresult:='<error>';
  4929. end;
  4930. end;
  4931. tmpresult:=tmpresult+')';
  4932. { And the type of the function result (void in case of a procedure and
  4933. constructor). }
  4934. if (proctypeoption in [potype_constructor,potype_class_constructor]) then
  4935. jvmaddencodedtype(voidtype,false,tmpresult,signature,founderror)
  4936. else if not jvmaddencodedtype(returndef,false,tmpresult,signature,founderror) then
  4937. { an internalerror here is also triggered in case of errors in the source code }
  4938. tmpresult:='<error>';
  4939. result:=tmpresult;
  4940. end;
  4941. {$endif jvm}
  4942. procedure tprocdef.setmangledname(const s : TSymStr);
  4943. begin
  4944. { This is not allowed anymore, the forward declaration
  4945. already needs to create the correct mangledname, no changes
  4946. afterwards are allowed (PFV) }
  4947. { Exception: interface definitions in mode macpas, since in that }
  4948. { case no reference to the old name can exist yet (JM) }
  4949. {$ifdef symansistr}
  4950. if _mangledname<>'' then
  4951. if ((m_mac in current_settings.modeswitches) and
  4952. (interfacedef)) then
  4953. _mangledname:=''
  4954. else
  4955. internalerror(200411171);
  4956. {$else symansistr}
  4957. if assigned(_mangledname) then
  4958. if ((m_mac in current_settings.modeswitches) and
  4959. (interfacedef)) then
  4960. stringdispose(_mangledname)
  4961. else
  4962. internalerror(200411171);
  4963. {$endif symansistr}
  4964. {$ifdef jvm}
  4965. { this routine can be called for compilerproces. can't set mangled
  4966. name since it must be calculated, but it uses import_name when set
  4967. -> set that one }
  4968. import_name:=stringdup(s);
  4969. include(procoptions,po_has_importname);
  4970. include(procoptions,po_has_mangledname);
  4971. {$else}
  4972. {$ifdef compress}
  4973. {$error add support for symansistr}
  4974. _mangledname:=stringdup(minilzw_encode(s));
  4975. {$else}
  4976. {$ifdef symansistr}
  4977. _mangledname:=s;
  4978. {$else symansistr}
  4979. _mangledname:=stringdup(s);
  4980. {$endif symansistr}
  4981. {$endif}
  4982. {$endif jvm}
  4983. include(procoptions,po_has_mangledname);
  4984. end;
  4985. {***************************************************************************
  4986. TPROCVARDEF
  4987. ***************************************************************************}
  4988. constructor tprocvardef.create(level:byte);
  4989. begin
  4990. inherited create(procvardef,level);
  4991. end;
  4992. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  4993. begin
  4994. inherited ppuload(procvardef,ppufile);
  4995. { load para symtable }
  4996. parast:=tparasymtable.create(self,ppufile.getbyte);
  4997. {$ifdef jvm}
  4998. ppufile.getderef(classdefderef);
  4999. {$endif}
  5000. tparasymtable(parast).ppuload(ppufile);
  5001. end;
  5002. function tprocvardef.getcopy : tstoreddef;
  5003. var
  5004. i : tcallercallee;
  5005. j : longint;
  5006. begin
  5007. result:=tprocvardef.create(parast.symtablelevel);
  5008. tprocvardef(result).returndef:=returndef;
  5009. tprocvardef(result).returndefderef:=returndefderef;
  5010. tprocvardef(result).parast:=parast.getcopy;
  5011. tprocvardef(result).savesize:=savesize;
  5012. { create paralist copy }
  5013. calcparas;
  5014. tprocvardef(result).paras:=tparalist.create(false);
  5015. tprocvardef(result).paras.count:=paras.count;
  5016. for j:=0 to paras.count-1 do
  5017. tprocvardef(result).paras[j]:=paras[j];
  5018. tprocvardef(result).proctypeoption:=proctypeoption;
  5019. tprocvardef(result).proccalloption:=proccalloption;
  5020. tprocvardef(result).procoptions:=procoptions;
  5021. tprocvardef(result).callerargareasize:=callerargareasize;
  5022. tprocvardef(result).calleeargareasize:=calleeargareasize;
  5023. tprocvardef(result).maxparacount:=maxparacount;
  5024. tprocvardef(result).minparacount:=minparacount;
  5025. for i:=low(tcallercallee) to high(tcallercallee) do
  5026. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  5027. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  5028. {$ifdef m68k}
  5029. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  5030. {$endif}
  5031. {$ifdef jvm}
  5032. tprocvardef(result).classdef:=classdef;
  5033. {$endif}
  5034. end;
  5035. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  5036. begin
  5037. inherited ppuwrite(ppufile);
  5038. { Save the para symtable level (necessary to distinguish nested
  5039. procvars) }
  5040. ppufile.putbyte(parast.symtablelevel);
  5041. {$ifdef jvm}
  5042. ppufile.putderef(classdefderef);
  5043. {$endif}
  5044. { Write this entry }
  5045. ppufile.writeentry(ibprocvardef);
  5046. { Save the para symtable, this is taken from the interface }
  5047. tparasymtable(parast).ppuwrite(ppufile);
  5048. end;
  5049. {$ifdef jvm}
  5050. procedure tprocvardef.buildderef;
  5051. begin
  5052. inherited buildderef;
  5053. classdefderef.build(classdef);
  5054. end;
  5055. procedure tprocvardef.deref;
  5056. begin
  5057. inherited deref;
  5058. classdef:=tobjectdef(classdefderef.resolve);
  5059. end;
  5060. {$endif}
  5061. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  5062. begin
  5063. case t of
  5064. gs_para :
  5065. GetSymtable:=parast;
  5066. else
  5067. GetSymtable:=nil;
  5068. end;
  5069. end;
  5070. function tprocvardef.size : asizeint;
  5071. var
  5072. far_code_extra_bytes: integer = 0;
  5073. far_data_extra_bytes: integer = 0;
  5074. begin
  5075. {$ifdef i8086}
  5076. if po_far in procoptions then
  5077. far_code_extra_bytes:=2;
  5078. if current_settings.x86memorymodel in x86_far_data_models then
  5079. far_data_extra_bytes:=2;
  5080. {$endif i8086}
  5081. if ((po_methodpointer in procoptions) or
  5082. is_nested_pd(self)) and
  5083. not(po_addressonly in procoptions) then
  5084. size:=2*sizeof(pint)+far_code_extra_bytes+far_data_extra_bytes
  5085. else
  5086. size:=sizeof(pint)+far_code_extra_bytes;
  5087. end;
  5088. function tprocvardef.is_methodpointer:boolean;
  5089. begin
  5090. result:=(po_methodpointer in procoptions);
  5091. end;
  5092. function tprocvardef.is_addressonly:boolean;
  5093. begin
  5094. result:=(not(po_methodpointer in procoptions) and
  5095. not is_nested_pd(self)) or
  5096. (po_addressonly in procoptions);
  5097. end;
  5098. function tprocvardef.getmangledparaname:TSymStr;
  5099. begin
  5100. if not(po_methodpointer in procoptions) then
  5101. if not is_nested_pd(self) then
  5102. result:='procvar'
  5103. else
  5104. result:='nestedprovar'
  5105. else
  5106. result:='procvarofobj'
  5107. end;
  5108. function tprocvardef.is_publishable : boolean;
  5109. begin
  5110. is_publishable:=(po_methodpointer in procoptions);
  5111. end;
  5112. function tprocvardef.GetTypeName : string;
  5113. var
  5114. s: string;
  5115. pno : tprocnameoptions;
  5116. begin
  5117. {$ifdef EXTDEBUG}
  5118. pno:=[pno_showhidden];
  5119. {$else EXTDEBUG}
  5120. pno:=[];
  5121. {$endif EXTDEBUG}
  5122. s:='<';
  5123. if po_classmethod in procoptions then
  5124. s := s+'class method type of'
  5125. else
  5126. if po_addressonly in procoptions then
  5127. s := s+'address of'
  5128. else
  5129. s := s+'procedure variable type of';
  5130. if assigned(returndef) and
  5131. (returndef<>voidtype) then
  5132. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  5133. else
  5134. s:=s+' procedure'+typename_paras(pno);
  5135. if po_methodpointer in procoptions then
  5136. s := s+' of object';
  5137. if is_nested_pd(self) then
  5138. s := s+' is nested';
  5139. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  5140. end;
  5141. {***************************************************************************
  5142. TOBJECTDEF
  5143. ***************************************************************************}
  5144. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef);
  5145. begin
  5146. inherited create(n,objectdef);
  5147. fcurrent_dispid:=0;
  5148. objecttype:=ot;
  5149. childof:=nil;
  5150. if objecttype=odt_helper then
  5151. owner.includeoption(sto_has_helper);
  5152. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  5153. { create space for vmt !! }
  5154. vmtentries:=TFPList.Create;
  5155. vmt_offset:=0;
  5156. set_parent(c);
  5157. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  5158. prepareguid;
  5159. { setup implemented interfaces }
  5160. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5161. ImplementedInterfaces:=TFPObjectList.Create(true)
  5162. else
  5163. ImplementedInterfaces:=nil;
  5164. writing_class_record_dbginfo:=false;
  5165. end;
  5166. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  5167. var
  5168. i,
  5169. implintfcount : longint;
  5170. d, getterd : tderef;
  5171. ImplIntf : TImplementedInterface;
  5172. vmtentry : pvmtentry;
  5173. begin
  5174. inherited ppuload(objectdef,ppufile);
  5175. objecttype:=tobjecttyp(ppufile.getbyte);
  5176. objextname:=stringdup(ppufile.getstring);
  5177. { only used for external Objective-C classes/protocols }
  5178. if (objextname^='') then
  5179. stringdispose(objextname);
  5180. symtable:=tObjectSymtable.create(self,objrealname^,0);
  5181. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  5182. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  5183. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  5184. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  5185. vmt_offset:=ppufile.getlongint;
  5186. ppufile.getderef(childofderef);
  5187. { load guid }
  5188. iidstr:=nil;
  5189. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5190. begin
  5191. new(iidguid);
  5192. ppufile.getguid(iidguid^);
  5193. iidstr:=stringdup(ppufile.getstring);
  5194. end;
  5195. abstractcnt:=ppufile.getlongint;
  5196. if objecttype=odt_helper then
  5197. ppufile.getderef(extendeddefderef);
  5198. vmtentries:=TFPList.Create;
  5199. vmtentries.count:=ppufile.getlongint;
  5200. for i:=0 to vmtentries.count-1 do
  5201. begin
  5202. ppufile.getderef(d);
  5203. new(vmtentry);
  5204. vmtentry^.procdef:=nil;
  5205. vmtentry^.procdefderef:=d;
  5206. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  5207. vmtentries[i]:=vmtentry;
  5208. end;
  5209. { load implemented interfaces }
  5210. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5211. begin
  5212. ImplementedInterfaces:=TFPObjectList.Create(true);
  5213. implintfcount:=ppufile.getlongint;
  5214. for i:=0 to implintfcount-1 do
  5215. begin
  5216. ppufile.getderef(d);
  5217. ppufile.getderef(getterd);
  5218. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  5219. ImplIntf.IOffset:=ppufile.getlongint;
  5220. byte(ImplIntf.IType):=ppufile.getbyte;
  5221. ImplementedInterfaces.Add(ImplIntf);
  5222. end;
  5223. end
  5224. else
  5225. ImplementedInterfaces:=nil;
  5226. if df_copied_def in defoptions then
  5227. ppufile.getderef(cloneddefderef)
  5228. else
  5229. tObjectSymtable(symtable).ppuload(ppufile);
  5230. { handles the predefined class tobject }
  5231. { the last TOBJECT which is loaded gets }
  5232. { it ! }
  5233. if (childof=nil) and
  5234. (objecttype in [odt_class,odt_javaclass]) and
  5235. (objname^='TOBJECT') then
  5236. class_tobject:=self;
  5237. if (childof=nil) and
  5238. (objecttype=odt_interfacecom) then
  5239. if (objname^='IUNKNOWN') then
  5240. interface_iunknown:=self
  5241. else
  5242. if (objname^='IDISPATCH') then
  5243. interface_idispatch:=self;
  5244. if (childof=nil) and
  5245. (objecttype=odt_objcclass) and
  5246. (objname^='PROTOCOL') then
  5247. objc_protocoltype:=self;
  5248. if (objecttype=odt_javaclass) and
  5249. not(oo_is_formal in objectoptions) then
  5250. begin
  5251. if (objname^='JLOBJECT') then
  5252. java_jlobject:=self
  5253. else if (objname^='JLTHROWABLE') then
  5254. java_jlthrowable:=self
  5255. else if (objname^='FPCBASERECORDTYPE') then
  5256. java_fpcbaserecordtype:=self
  5257. else if (objname^='JLSTRING') then
  5258. java_jlstring:=self
  5259. else if (objname^='ANSISTRINGCLASS') then
  5260. java_ansistring:=self
  5261. else if (objname^='SHORTSTRINGCLASS') then
  5262. java_shortstring:=self
  5263. else if (objname^='JLENUM') then
  5264. java_jlenum:=self
  5265. else if (objname^='JUENUMSET') then
  5266. java_juenumset:=self
  5267. else if (objname^='FPCBITSET') then
  5268. java_jubitset:=self
  5269. else if (objname^='FPCBASEPROCVARTYPE') then
  5270. java_procvarbase:=self;
  5271. end;
  5272. writing_class_record_dbginfo:=false;
  5273. end;
  5274. destructor tobjectdef.destroy;
  5275. begin
  5276. if assigned(symtable) then
  5277. begin
  5278. symtable.free;
  5279. symtable:=nil;
  5280. end;
  5281. stringdispose(objextname);
  5282. stringdispose(iidstr);
  5283. if assigned(ImplementedInterfaces) then
  5284. begin
  5285. ImplementedInterfaces.free;
  5286. ImplementedInterfaces:=nil;
  5287. end;
  5288. if assigned(iidguid) then
  5289. begin
  5290. dispose(iidguid);
  5291. iidguid:=nil;
  5292. end;
  5293. if assigned(vmtentries) then
  5294. begin
  5295. resetvmtentries;
  5296. vmtentries.free;
  5297. vmtentries:=nil;
  5298. end;
  5299. if assigned(vmcallstaticinfo) then
  5300. begin
  5301. freemem(vmcallstaticinfo);
  5302. vmcallstaticinfo:=nil;
  5303. end;
  5304. inherited destroy;
  5305. end;
  5306. function tobjectdef.getcopy : tstoreddef;
  5307. var
  5308. i : longint;
  5309. begin
  5310. result:=tobjectdef.create(objecttype,objrealname^,childof);
  5311. { the constructor allocates a symtable which we release to avoid memory leaks }
  5312. tobjectdef(result).symtable.free;
  5313. tobjectdef(result).symtable:=symtable.getcopy;
  5314. if assigned(objextname) then
  5315. tobjectdef(result).objextname:=stringdup(objextname^);
  5316. if assigned(import_lib) then
  5317. tobjectdef(result).import_lib:=stringdup(import_lib^);
  5318. tobjectdef(result).objectoptions:=objectoptions;
  5319. include(tobjectdef(result).defoptions,df_copied_def);
  5320. tobjectdef(result).extendeddef:=extendeddef;
  5321. if assigned(tcinitcode) then
  5322. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  5323. tobjectdef(result).vmt_offset:=vmt_offset;
  5324. if assigned(iidguid) then
  5325. begin
  5326. new(tobjectdef(result).iidguid);
  5327. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  5328. end;
  5329. if assigned(iidstr) then
  5330. tobjectdef(result).iidstr:=stringdup(iidstr^);
  5331. tobjectdef(result).abstractcnt:=abstractcnt;
  5332. if assigned(ImplementedInterfaces) then
  5333. begin
  5334. for i:=0 to ImplementedInterfaces.count-1 do
  5335. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  5336. end;
  5337. if assigned(vmtentries) then
  5338. begin
  5339. tobjectdef(result).vmtentries:=TFPList.Create;
  5340. tobjectdef(result).copyvmtentries(self);
  5341. end;
  5342. end;
  5343. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  5344. var
  5345. i : longint;
  5346. vmtentry : pvmtentry;
  5347. ImplIntf : TImplementedInterface;
  5348. old_do_indirect_crc: boolean;
  5349. begin
  5350. { if class1 in unit A changes, and class2 in unit B inherits from it
  5351. (so unit B uses unit A), then unit B with class2 will be recompiled.
  5352. However, if there is also a class3 in unit C that only depends on
  5353. unit B, then unit C will not be recompiled because nothing changed
  5354. to the interface of unit B. Nevertheless, unit C can indirectly
  5355. depend on unit A via derefs, and these must be updated -> the
  5356. indirect crc keeps track of such changes. }
  5357. old_do_indirect_crc:=ppufile.do_indirect_crc;
  5358. ppufile.do_indirect_crc:=true;
  5359. inherited ppuwrite(ppufile);
  5360. ppufile.putbyte(byte(objecttype));
  5361. if assigned(objextname) then
  5362. ppufile.putstring(objextname^)
  5363. else
  5364. ppufile.putstring('');
  5365. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  5366. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  5367. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  5368. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  5369. ppufile.putlongint(vmt_offset);
  5370. ppufile.putderef(childofderef);
  5371. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5372. begin
  5373. ppufile.putguid(iidguid^);
  5374. ppufile.putstring(iidstr^);
  5375. end;
  5376. ppufile.putlongint(abstractcnt);
  5377. if objecttype=odt_helper then
  5378. ppufile.putderef(extendeddefderef);
  5379. ppufile.putlongint(vmtentries.count);
  5380. for i:=0 to vmtentries.count-1 do
  5381. begin
  5382. vmtentry:=pvmtentry(vmtentries[i]);
  5383. ppufile.putderef(vmtentry^.procdefderef);
  5384. ppufile.putbyte(byte(vmtentry^.visibility));
  5385. end;
  5386. if assigned(ImplementedInterfaces) then
  5387. begin
  5388. ppufile.putlongint(ImplementedInterfaces.Count);
  5389. for i:=0 to ImplementedInterfaces.Count-1 do
  5390. begin
  5391. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  5392. ppufile.putderef(ImplIntf.intfdefderef);
  5393. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  5394. ppufile.putlongint(ImplIntf.Ioffset);
  5395. ppufile.putbyte(byte(ImplIntf.IType));
  5396. end;
  5397. end;
  5398. if df_copied_def in defoptions then
  5399. ppufile.putderef(cloneddefderef);
  5400. ppufile.writeentry(ibobjectdef);
  5401. if not(df_copied_def in defoptions) then
  5402. tObjectSymtable(symtable).ppuwrite(ppufile);
  5403. ppufile.do_indirect_crc:=old_do_indirect_crc;
  5404. end;
  5405. function tobjectdef.GetTypeName:string;
  5406. begin
  5407. { in this case we will go in endless recursion, because then }
  5408. { there is no tsym associated yet with the def. It can occur }
  5409. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  5410. { instead of the actual type name }
  5411. if not assigned(typesym) then
  5412. result:='<Currently Parsed Class>'
  5413. else
  5414. result:=typesymbolprettyname;
  5415. end;
  5416. procedure tobjectdef.buildderef;
  5417. var
  5418. i : longint;
  5419. vmtentry : pvmtentry;
  5420. begin
  5421. inherited buildderef;
  5422. childofderef.build(childof);
  5423. if df_copied_def in defoptions then
  5424. cloneddefderef.build(symtable.defowner)
  5425. else
  5426. tstoredsymtable(symtable).buildderef;
  5427. if objecttype=odt_helper then
  5428. extendeddefderef.build(extendeddef);
  5429. for i:=0 to vmtentries.count-1 do
  5430. begin
  5431. vmtentry:=pvmtentry(vmtentries[i]);
  5432. vmtentry^.procdefderef.build(vmtentry^.procdef);
  5433. end;
  5434. if assigned(ImplementedInterfaces) then
  5435. begin
  5436. for i:=0 to ImplementedInterfaces.count-1 do
  5437. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  5438. end;
  5439. end;
  5440. procedure tobjectdef.deref;
  5441. var
  5442. i : longint;
  5443. vmtentry : pvmtentry;
  5444. begin
  5445. inherited deref;
  5446. childof:=tobjectdef(childofderef.resolve);
  5447. if df_copied_def in defoptions then
  5448. begin
  5449. cloneddef:=tobjectdef(cloneddefderef.resolve);
  5450. symtable:=cloneddef.symtable.getcopy;
  5451. end
  5452. else
  5453. tstoredsymtable(symtable).deref;
  5454. fillgenericparas(symtable);
  5455. if objecttype=odt_helper then
  5456. extendeddef:=tdef(extendeddefderef.resolve);
  5457. for i:=0 to vmtentries.count-1 do
  5458. begin
  5459. vmtentry:=pvmtentry(vmtentries[i]);
  5460. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  5461. end;
  5462. if assigned(ImplementedInterfaces) then
  5463. begin
  5464. for i:=0 to ImplementedInterfaces.count-1 do
  5465. TImplementedInterface(ImplementedInterfaces[i]).deref;
  5466. end;
  5467. end;
  5468. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  5469. var
  5470. pd: tprocdef absolute def;
  5471. st: tsymtable;
  5472. psym: tsym;
  5473. nname: TIDString;
  5474. begin
  5475. if (tdef(def).typ<>procdef) then
  5476. exit;
  5477. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  5478. owner = symtable in which objcclassdef is defined
  5479. }
  5480. st:=pd.owner.defowner.owner;
  5481. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  5482. { check for an existing procsym with our special name }
  5483. psym:=tsym(st.find(nname));
  5484. if not assigned(psym) then
  5485. begin
  5486. psym:=tprocsym.create(nname);
  5487. { avoid warning about this symbol being unused }
  5488. psym.IncRefCount;
  5489. { don't check for duplicates:
  5490. a) we checked above
  5491. b) in case we are in the implementation section of a unit, this
  5492. will also check for this symbol in the interface section
  5493. (since you normally cannot have symbols with the same name
  5494. both interface and implementation), and it's possible to
  5495. have class helpers for the same class in the interface and
  5496. in the implementation, and they cannot be merged since only
  5497. the once in the interface must be saved to the ppu/visible
  5498. from other units }
  5499. st.insert(psym,false);
  5500. end
  5501. else if (psym.typ<>procsym) then
  5502. internalerror(2009111501);
  5503. { add ourselves to this special procsym }
  5504. tprocsym(psym).procdeflist.add(def);
  5505. end;
  5506. procedure tobjectdef.buildderefimpl;
  5507. begin
  5508. inherited buildderefimpl;
  5509. if not (df_copied_def in defoptions) then
  5510. tstoredsymtable(symtable).buildderefimpl;
  5511. end;
  5512. procedure tobjectdef.derefimpl;
  5513. begin
  5514. inherited derefimpl;
  5515. if not (df_copied_def in defoptions) then
  5516. tstoredsymtable(symtable).derefimpl;
  5517. { the procdefs are not owned by the class helper procsyms, so they
  5518. are not stored/restored either -> re-add them here }
  5519. if (objecttype=odt_objcclass) or
  5520. (oo_is_classhelper in objectoptions) then
  5521. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  5522. end;
  5523. procedure tobjectdef.resetvmtentries;
  5524. var
  5525. i : longint;
  5526. begin
  5527. for i:=0 to vmtentries.Count-1 do
  5528. Dispose(pvmtentry(vmtentries[i]));
  5529. vmtentries.clear;
  5530. end;
  5531. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  5532. var
  5533. i : longint;
  5534. vmtentry : pvmtentry;
  5535. begin
  5536. resetvmtentries;
  5537. vmtentries.count:=objdef.vmtentries.count;
  5538. for i:=0 to objdef.vmtentries.count-1 do
  5539. begin
  5540. new(vmtentry);
  5541. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  5542. vmtentries[i]:=vmtentry;
  5543. end;
  5544. end;
  5545. function tobjectdef.getparentdef:tdef;
  5546. begin
  5547. { TODO: Remove getparentdef hack}
  5548. { With 2 forward declared classes with the child class before the
  5549. parent class the child class is written earlier to the ppu. Leaving it
  5550. possible to have a reference to the parent class for property overriding,
  5551. but the parent class still has the childof not resolved yet (PFV) }
  5552. if childof=nil then
  5553. childof:=tobjectdef(childofderef.resolve);
  5554. result:=childof;
  5555. end;
  5556. procedure tobjectdef.prepareguid;
  5557. begin
  5558. { set up guid }
  5559. if not assigned(iidguid) then
  5560. begin
  5561. new(iidguid);
  5562. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  5563. end;
  5564. { setup iidstring }
  5565. if not assigned(iidstr) then
  5566. iidstr:=stringdup(''); { default is empty string }
  5567. end;
  5568. procedure tobjectdef.set_parent( c : tobjectdef);
  5569. begin
  5570. if assigned(childof) then
  5571. exit;
  5572. childof:=c;
  5573. if not assigned(c) then
  5574. exit;
  5575. { inherit options and status }
  5576. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  5577. { initially has the same number of abstract methods as the parent }
  5578. abstractcnt:=c.abstractcnt;
  5579. { add the data of the anchestor class/object }
  5580. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  5581. begin
  5582. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  5583. { inherit recordalignment }
  5584. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  5585. { if both the parent and this record use C-alignment, also inherit
  5586. the current field alignment }
  5587. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  5588. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  5589. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  5590. { the padding is not inherited for Objective-C classes (maybe not
  5591. for cppclass either?) }
  5592. if objecttype=odt_objcclass then
  5593. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  5594. if (oo_has_vmt in objectoptions) and
  5595. (oo_has_vmt in c.objectoptions) then
  5596. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  5597. { if parent has a vmt field then the offset is the same for the child PM }
  5598. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  5599. begin
  5600. vmt_offset:=c.vmt_offset;
  5601. include(objectoptions,oo_has_vmt);
  5602. end;
  5603. end;
  5604. end;
  5605. procedure tobjectdef.insertvmt;
  5606. var
  5607. vs: tfieldvarsym;
  5608. begin
  5609. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5610. exit;
  5611. if (oo_has_vmt in objectoptions) then
  5612. internalerror(12345)
  5613. else
  5614. begin
  5615. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  5616. tObjectSymtable(symtable).fieldalignment);
  5617. if (tf_requires_proper_alignment in target_info.flags) then
  5618. begin
  5619. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  5620. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  5621. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  5622. end;
  5623. vs:=tfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  5624. hidesym(vs);
  5625. tObjectSymtable(symtable).insert(vs);
  5626. tObjectSymtable(symtable).addfield(vs,vis_hidden);
  5627. if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  5628. vmt_offset:=vs.fieldoffset
  5629. else
  5630. vmt_offset:=vs.fieldoffset div 8;
  5631. include(objectoptions,oo_has_vmt);
  5632. end;
  5633. end;
  5634. procedure tobjectdef.check_forwards;
  5635. begin
  5636. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  5637. inherited;
  5638. if (oo_is_forward in objectoptions) then
  5639. begin
  5640. { ok, in future, the forward can be resolved }
  5641. Message1(sym_e_class_forward_not_resolved,objrealname^);
  5642. exclude(objectoptions,oo_is_forward);
  5643. end;
  5644. end;
  5645. function tobjectdef.find_destructor: tprocdef;
  5646. var
  5647. objdef: tobjectdef;
  5648. begin
  5649. objdef:=self;
  5650. while assigned(objdef) do
  5651. begin
  5652. result:=objdef.find_procdef_bytype(potype_destructor);
  5653. if assigned(result) then
  5654. exit;
  5655. objdef:=objdef.childof;
  5656. end;
  5657. result:=nil;
  5658. end;
  5659. function tobjectdef.implements_any_interfaces: boolean;
  5660. begin
  5661. result := (ImplementedInterfaces.Count > 0) or
  5662. (assigned(childof) and childof.implements_any_interfaces);
  5663. end;
  5664. function tobjectdef.size : asizeint;
  5665. begin
  5666. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5667. result:=sizeof(pint)
  5668. else
  5669. result:=tObjectSymtable(symtable).datasize;
  5670. end;
  5671. function tobjectdef.alignment:shortint;
  5672. begin
  5673. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5674. alignment:=sizeof(pint)
  5675. else
  5676. alignment:=tObjectSymtable(symtable).recordalignment;
  5677. end;
  5678. function tobjectdef.vmtmethodoffset(index:longint):longint;
  5679. var
  5680. codeptrsize: Integer;
  5681. begin
  5682. {$ifdef i8086}
  5683. if current_settings.x86memorymodel in x86_far_code_models then
  5684. codeptrsize:=4
  5685. else
  5686. codeptrsize:=2;
  5687. {$else i8086}
  5688. codeptrsize:=sizeof(pint);
  5689. {$endif i8086}
  5690. { for offset of methods for classes, see rtl/inc/objpash.inc }
  5691. case objecttype of
  5692. odt_class:
  5693. { the +2*sizeof(pint) is size and -size }
  5694. vmtmethodoffset:=index*codeptrsize+10*sizeof(pint)+2*sizeof(pint);
  5695. odt_helper,
  5696. odt_objcclass,
  5697. odt_objcprotocol:
  5698. vmtmethodoffset:=0;
  5699. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  5700. vmtmethodoffset:=index*codeptrsize;
  5701. odt_javaclass,
  5702. odt_interfacejava:
  5703. { invalid }
  5704. vmtmethodoffset:=-1;
  5705. else
  5706. {$ifdef WITHDMT}
  5707. vmtmethodoffset:=index*codeptrsize+4*sizeof(pint);
  5708. {$else WITHDMT}
  5709. vmtmethodoffset:=index*codeptrsize+3*sizeof(pint);
  5710. {$endif WITHDMT}
  5711. end;
  5712. end;
  5713. function tobjectdef.vmt_mangledname : TSymStr;
  5714. begin
  5715. if not(oo_has_vmt in objectoptions) then
  5716. Message1(parser_n_object_has_no_vmt,objrealname^);
  5717. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  5718. end;
  5719. function tobjectdef.needs_inittable : boolean;
  5720. var
  5721. hp : tobjectdef;
  5722. begin
  5723. case objecttype of
  5724. odt_helper,
  5725. odt_class :
  5726. needs_inittable:=false;
  5727. odt_dispinterface,
  5728. odt_interfacecom:
  5729. needs_inittable:=true;
  5730. odt_interfacecorba:
  5731. begin
  5732. hp:=childof;
  5733. while assigned(hp) do
  5734. begin
  5735. if hp=interface_iunknown then
  5736. begin
  5737. needs_inittable:=true;
  5738. exit;
  5739. end;
  5740. hp:=hp.childof;
  5741. end;
  5742. needs_inittable:=false;
  5743. end;
  5744. odt_object:
  5745. needs_inittable:=
  5746. tObjectSymtable(symtable).needs_init_final or
  5747. (assigned(childof) and
  5748. childof.needs_inittable);
  5749. odt_cppclass,
  5750. odt_objcclass,
  5751. odt_objcprotocol,
  5752. odt_javaclass,
  5753. odt_interfacejava:
  5754. needs_inittable:=false;
  5755. else
  5756. internalerror(200108267);
  5757. end;
  5758. end;
  5759. function tobjectdef.needs_separate_initrtti : boolean;
  5760. begin
  5761. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  5762. end;
  5763. function tobjectdef.rtti_mangledname(rt: trttitype): string;
  5764. begin
  5765. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  5766. result:=inherited rtti_mangledname(rt)
  5767. else
  5768. begin
  5769. { necessary in case of a dynamic array of nsobject, or
  5770. if an nsobject field appears in a record that needs
  5771. init/finalisation }
  5772. if rt=initrtti then
  5773. begin
  5774. result:=voidpointertype.rtti_mangledname(rt);
  5775. exit;
  5776. end;
  5777. if not(target_info.system in systems_objc_nfabi) then
  5778. begin
  5779. result:=target_asm.labelprefix;
  5780. case objecttype of
  5781. odt_objcclass:
  5782. begin
  5783. case rt of
  5784. objcclassrtti:
  5785. if not(oo_is_classhelper in objectoptions) then
  5786. result:=result+'_OBJC_CLASS_'
  5787. else
  5788. result:=result+'_OBJC_CATEGORY_';
  5789. objcmetartti:
  5790. if not(oo_is_classhelper in objectoptions) then
  5791. result:=result+'_OBJC_METACLASS_'
  5792. else
  5793. internalerror(2009111511);
  5794. else
  5795. internalerror(2009092302);
  5796. end;
  5797. end;
  5798. odt_objcprotocol:
  5799. result:=result+'_OBJC_PROTOCOL_';
  5800. end;
  5801. end
  5802. else
  5803. begin
  5804. case objecttype of
  5805. odt_objcclass:
  5806. begin
  5807. if (oo_is_classhelper in objectoptions) and
  5808. (rt<>objcclassrtti) then
  5809. internalerror(2009111512);
  5810. case rt of
  5811. objcclassrtti:
  5812. if not(oo_is_classhelper in objectoptions) then
  5813. result:='_OBJC_CLASS_$_'
  5814. else
  5815. result:='_OBJC_$_CATEGORY_';
  5816. objcmetartti:
  5817. result:='_OBJC_METACLASS_$_';
  5818. objcclassrortti:
  5819. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  5820. objcmetarortti:
  5821. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  5822. else
  5823. internalerror(2009092303);
  5824. end;
  5825. end;
  5826. odt_objcprotocol:
  5827. begin
  5828. result:=lower(target_asm.labelprefix);
  5829. case rt of
  5830. objcclassrtti:
  5831. result:=result+'_OBJC_PROTOCOL_$_';
  5832. objcmetartti:
  5833. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  5834. else
  5835. internalerror(2009092501);
  5836. end;
  5837. end;
  5838. else
  5839. internalerror(2013113005);
  5840. end;
  5841. end;
  5842. result:=result+objextname^;
  5843. end;
  5844. end;
  5845. function tobjectdef.members_need_inittable : boolean;
  5846. begin
  5847. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  5848. end;
  5849. function tobjectdef.is_publishable : boolean;
  5850. begin
  5851. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  5852. end;
  5853. function tobjectdef.get_next_dispid: longint;
  5854. begin
  5855. inc(fcurrent_dispid);
  5856. result:=fcurrent_dispid;
  5857. end;
  5858. function tobjectdef.search_enumerator_get: tprocdef;
  5859. begin
  5860. result:=inherited;
  5861. if not assigned(result) and assigned(childof) then
  5862. result:=childof.search_enumerator_get;
  5863. end;
  5864. function tobjectdef.search_enumerator_move: tprocdef;
  5865. begin
  5866. result:=inherited;
  5867. if not assigned(result) and assigned(childof) then
  5868. result:=childof.search_enumerator_move;
  5869. end;
  5870. function tobjectdef.search_enumerator_current: tsym;
  5871. begin
  5872. result:=inherited;
  5873. if not assigned(result) and assigned(childof) then
  5874. result:=childof.search_enumerator_current;
  5875. end;
  5876. procedure tobjectdef.register_created_classref_type;
  5877. begin
  5878. if not classref_created_in_current_module then
  5879. begin
  5880. classref_created_in_current_module:=true;
  5881. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  5882. end;
  5883. end;
  5884. procedure tobjectdef.register_created_object_type;
  5885. begin
  5886. if not created_in_current_module then
  5887. begin
  5888. created_in_current_module:=true;
  5889. current_module.wpoinfo.addcreatedobjtype(self);
  5890. end;
  5891. end;
  5892. procedure tobjectdef.register_maybe_created_object_type;
  5893. begin
  5894. { if we know it has been created for sure, no need
  5895. to also record that it maybe can be created in
  5896. this module
  5897. }
  5898. if not (created_in_current_module) and
  5899. not (maybe_created_in_current_module) then
  5900. begin
  5901. maybe_created_in_current_module:=true;
  5902. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  5903. end;
  5904. end;
  5905. procedure tobjectdef.register_vmt_call(index: longint);
  5906. begin
  5907. if (is_object(self) or is_class(self)) then
  5908. current_module.wpoinfo.addcalledvmtentry(self,index);
  5909. end;
  5910. procedure check_and_finish_msg(data: tobject; arg: pointer);
  5911. var
  5912. def: tdef absolute data;
  5913. pd: tprocdef absolute data;
  5914. i,
  5915. paracount: longint;
  5916. begin
  5917. if (def.typ=procdef) then
  5918. begin
  5919. { add all messages also under a dummy name to the symtable in
  5920. which the objcclass/protocol/category is declared, so they can
  5921. be called via id.<name>
  5922. }
  5923. create_class_helper_for_procdef(pd,nil);
  5924. { we have to wait until now to set the mangled name because it
  5925. depends on the (possibly external) class name, which is defined
  5926. at the very end. }
  5927. if not(po_msgstr in pd.procoptions) then
  5928. begin
  5929. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  5930. { recover to avoid internalerror later on }
  5931. include(pd.procoptions,po_msgstr);
  5932. pd.messageinf.str:=stringdup('MissingDeclaration');
  5933. end;
  5934. { Mangled name is already set in case this is a copy of
  5935. another type. }
  5936. if not(po_has_mangledname in pd.procoptions) then
  5937. begin
  5938. { check whether the number of formal parameters is correct,
  5939. and whether they have valid Objective-C types }
  5940. paracount:=0;
  5941. for i:=1 to length(pd.messageinf.str^) do
  5942. if pd.messageinf.str^[i]=':' then
  5943. inc(paracount);
  5944. for i:=0 to pd.paras.count-1 do
  5945. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  5946. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  5947. dec(paracount);
  5948. if (paracount<>0) then
  5949. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  5950. pd.setmangledname(pd.objcmangledname);
  5951. end
  5952. else
  5953. { all checks already done }
  5954. exit;
  5955. if not(oo_is_external in pd.struct.objectoptions) then
  5956. begin
  5957. if (po_varargs in pd.procoptions) then
  5958. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  5959. else
  5960. begin
  5961. { check for "array of const" parameters }
  5962. for i:=0 to pd.parast.symlist.count-1 do
  5963. begin
  5964. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  5965. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  5966. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  5967. end;
  5968. end;
  5969. end;
  5970. end;
  5971. end;
  5972. procedure mark_private_fields_used(data: tobject; arg: pointer);
  5973. var
  5974. sym: tsym absolute data;
  5975. begin
  5976. if (sym.typ=fieldvarsym) and
  5977. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  5978. sym.IncRefCount;
  5979. end;
  5980. procedure tobjectdef.finish_objc_data;
  5981. begin
  5982. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  5983. if (oo_is_external in objectoptions) then
  5984. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  5985. end;
  5986. procedure verify_objc_vardef(data: tobject; arg: pointer);
  5987. var
  5988. sym: tabstractvarsym absolute data;
  5989. res: pboolean absolute arg;
  5990. founderrordef: tdef;
  5991. begin
  5992. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  5993. exit;
  5994. if (sym.typ=paravarsym) and
  5995. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  5996. is_array_of_const(tparavarsym(sym).vardef)) then
  5997. exit;
  5998. if not objcchecktype(sym.vardef,founderrordef) then
  5999. begin
  6000. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  6001. res^:=false;
  6002. end;
  6003. end;
  6004. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  6005. var
  6006. def: tdef absolute data;
  6007. res: pboolean absolute arg;
  6008. founderrordef: tdef;
  6009. begin
  6010. if (def.typ<>procdef) then
  6011. exit;
  6012. { check parameter types for validity }
  6013. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  6014. { check the result type for validity }
  6015. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  6016. begin
  6017. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  6018. res^:=false;
  6019. end;
  6020. end;
  6021. function tobjectdef.check_objc_types: boolean;
  6022. begin
  6023. { done in separate step from finish_objc_data, because when
  6024. finish_objc_data is called, not all forwarddefs have been resolved
  6025. yet and we need to know all types here }
  6026. result:=true;
  6027. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  6028. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  6029. end;
  6030. procedure do_cpp_import_info(data: tobject; arg: pointer);
  6031. var
  6032. def: tdef absolute data;
  6033. pd: tprocdef absolute data;
  6034. begin
  6035. if (def.typ=procdef) then
  6036. begin
  6037. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  6038. if (oo_is_external in pd.struct.objectoptions) then
  6039. begin
  6040. { copied from psub.read_proc }
  6041. if assigned(tobjectdef(pd.struct).import_lib) then
  6042. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  6043. else
  6044. begin
  6045. { add import name to external list for DLL scanning }
  6046. if tf_has_dllscanner in target_info.flags then
  6047. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  6048. end;
  6049. end;
  6050. end;
  6051. end;
  6052. procedure tobjectdef.finish_cpp_data;
  6053. begin
  6054. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  6055. end;
  6056. {****************************************************************************
  6057. TImplementedInterface
  6058. ****************************************************************************}
  6059. function TImplementedInterface.GetIOffset: longint;
  6060. begin
  6061. if (fIOffset=-1) and
  6062. (IType in [etFieldValue,etFieldValueClass]) then
  6063. result:=tfieldvarsym(ImplementsField).fieldoffset
  6064. else
  6065. result:=fIOffset;
  6066. end;
  6067. constructor TImplementedInterface.create(aintf: tobjectdef);
  6068. begin
  6069. inherited create;
  6070. intfdef:=aintf;
  6071. IOffset:=-1;
  6072. IType:=etStandard;
  6073. NameMappings:=nil;
  6074. procdefs:=nil;
  6075. end;
  6076. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  6077. begin
  6078. inherited create;
  6079. intfdef:=nil;
  6080. intfdefderef:=intfd;
  6081. ImplementsGetterDeref:=getterd;
  6082. IOffset:=-1;
  6083. IType:=etStandard;
  6084. NameMappings:=nil;
  6085. procdefs:=nil;
  6086. end;
  6087. destructor TImplementedInterface.destroy;
  6088. var
  6089. i : longint;
  6090. mappedname : pshortstring;
  6091. begin
  6092. if assigned(NameMappings) then
  6093. begin
  6094. for i:=0 to NameMappings.Count-1 do
  6095. begin
  6096. mappedname:=pshortstring(NameMappings[i]);
  6097. stringdispose(mappedname);
  6098. end;
  6099. NameMappings.free;
  6100. NameMappings:=nil;
  6101. end;
  6102. if assigned(procdefs) then
  6103. begin
  6104. procdefs.free;
  6105. procdefs:=nil;
  6106. end;
  6107. inherited destroy;
  6108. end;
  6109. procedure TImplementedInterface.buildderef;
  6110. begin
  6111. intfdefderef.build(intfdef);
  6112. ImplementsGetterDeref.build(ImplementsGetter);
  6113. end;
  6114. procedure TImplementedInterface.deref;
  6115. begin
  6116. intfdef:=tobjectdef(intfdefderef.resolve);
  6117. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  6118. end;
  6119. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  6120. begin
  6121. if not assigned(NameMappings) then
  6122. NameMappings:=TFPHashList.Create;
  6123. NameMappings.Add(origname,stringdup(newname));
  6124. end;
  6125. function TImplementedInterface.GetMapping(const origname: string):string;
  6126. var
  6127. mappedname : pshortstring;
  6128. begin
  6129. result:='';
  6130. if not assigned(NameMappings) then
  6131. exit;
  6132. mappedname:=PShortstring(NameMappings.Find(origname));
  6133. if assigned(mappedname) then
  6134. result:=mappedname^;
  6135. end;
  6136. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  6137. begin
  6138. if not assigned(procdefs) then
  6139. procdefs:=TFPObjectList.Create(false);
  6140. { duplicate entries must be stored, because multiple }
  6141. { interfaces can declare methods with the same name }
  6142. { and all of these get their own VMT entry }
  6143. procdefs.Add(pd);
  6144. end;
  6145. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  6146. var
  6147. i : longint;
  6148. begin
  6149. result:=false;
  6150. { interfaces being implemented through delegation are not mergable (FK) }
  6151. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  6152. exit;
  6153. weight:=0;
  6154. { empty interface is mergeable }
  6155. if ProcDefs.Count=0 then
  6156. begin
  6157. result:=true;
  6158. exit;
  6159. end;
  6160. { The interface to merge must at least the number of
  6161. procedures of this interface }
  6162. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  6163. exit;
  6164. for i:=0 to ProcDefs.Count-1 do
  6165. begin
  6166. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  6167. exit;
  6168. end;
  6169. weight:=ProcDefs.Count;
  6170. result:=true;
  6171. end;
  6172. function TImplementedInterface.getcopy:TImplementedInterface;
  6173. begin
  6174. Result:=TImplementedInterface.Create(nil);
  6175. { 1) the procdefs list will be freed once for each copy
  6176. 2) since the procdefs list owns its elements, those will also be freed for each copy
  6177. 3) idem for the name mappings
  6178. }
  6179. { warning: this is completely wrong on so many levels...
  6180. Move(pointer(self)^,pointer(result)^,InstanceSize);
  6181. We need to make clean copies of the different fields
  6182. this is not implemented yet, and thus we generate an internal
  6183. error instead PM 2011-06-14 }
  6184. internalerror(2011061401);
  6185. end;
  6186. {****************************************************************************
  6187. TFORWARDDEF
  6188. ****************************************************************************}
  6189. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  6190. begin
  6191. inherited create(forwarddef);
  6192. tosymname:=stringdup(s);
  6193. forwardpos:=pos;
  6194. end;
  6195. function tforwarddef.GetTypeName:string;
  6196. begin
  6197. GetTypeName:='unresolved forward to '+tosymname^;
  6198. end;
  6199. destructor tforwarddef.destroy;
  6200. begin
  6201. stringdispose(tosymname);
  6202. inherited destroy;
  6203. end;
  6204. function tforwarddef.getcopy:tstoreddef;
  6205. begin
  6206. result:=tforwarddef.create(tosymname^, forwardpos);
  6207. end;
  6208. {****************************************************************************
  6209. TUNDEFINEDDEF
  6210. ****************************************************************************}
  6211. constructor tundefineddef.create;
  6212. begin
  6213. inherited create(undefineddef);
  6214. end;
  6215. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  6216. begin
  6217. inherited ppuload(undefineddef,ppufile);
  6218. end;
  6219. function tundefineddef.GetTypeName:string;
  6220. begin
  6221. GetTypeName:='<undefined type>';
  6222. end;
  6223. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  6224. begin
  6225. inherited ppuwrite(ppufile);
  6226. ppufile.writeentry(ibundefineddef);
  6227. end;
  6228. {****************************************************************************
  6229. TERRORDEF
  6230. ****************************************************************************}
  6231. constructor terrordef.create;
  6232. begin
  6233. inherited create(errordef);
  6234. { prevent consecutive faults }
  6235. savesize:=1;
  6236. end;
  6237. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  6238. begin
  6239. { Can't write errordefs to ppu }
  6240. internalerror(200411063);
  6241. end;
  6242. function terrordef.GetTypeName:string;
  6243. begin
  6244. GetTypeName:='<erroneous type>';
  6245. end;
  6246. function terrordef.getmangledparaname:TSymStr;
  6247. begin
  6248. getmangledparaname:='error';
  6249. end;
  6250. {****************************************************************************
  6251. Definition Helpers
  6252. ****************************************************************************}
  6253. function is_interfacecom(def: tdef): boolean;
  6254. begin
  6255. is_interfacecom:=
  6256. assigned(def) and
  6257. (def.typ=objectdef) and
  6258. (tobjectdef(def).objecttype=odt_interfacecom);
  6259. end;
  6260. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  6261. begin
  6262. is_interfacecom_or_dispinterface:=
  6263. assigned(def) and
  6264. (def.typ=objectdef) and
  6265. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  6266. end;
  6267. function is_any_interface_kind(def: tdef): boolean;
  6268. begin
  6269. result:=
  6270. assigned(def) and
  6271. (def.typ=objectdef) and
  6272. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  6273. is_objccategory(def));
  6274. end;
  6275. function is_interfacecorba(def: tdef): boolean;
  6276. begin
  6277. is_interfacecorba:=
  6278. assigned(def) and
  6279. (def.typ=objectdef) and
  6280. (tobjectdef(def).objecttype=odt_interfacecorba);
  6281. end;
  6282. function is_interface(def: tdef): boolean;
  6283. begin
  6284. is_interface:=
  6285. assigned(def) and
  6286. (def.typ=objectdef) and
  6287. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  6288. end;
  6289. function is_dispinterface(def: tdef): boolean;
  6290. begin
  6291. result:=
  6292. assigned(def) and
  6293. (def.typ=objectdef) and
  6294. (tobjectdef(def).objecttype=odt_dispinterface);
  6295. end;
  6296. function is_class(def: tdef): boolean;
  6297. begin
  6298. is_class:=
  6299. assigned(def) and
  6300. (def.typ=objectdef) and
  6301. (tobjectdef(def).objecttype=odt_class);
  6302. end;
  6303. function is_object(def: tdef): boolean;
  6304. begin
  6305. is_object:=
  6306. assigned(def) and
  6307. (def.typ=objectdef) and
  6308. (tobjectdef(def).objecttype=odt_object);
  6309. end;
  6310. function is_cppclass(def: tdef): boolean;
  6311. begin
  6312. is_cppclass:=
  6313. assigned(def) and
  6314. (def.typ=objectdef) and
  6315. (tobjectdef(def).objecttype=odt_cppclass);
  6316. end;
  6317. function is_objcclass(def: tdef): boolean;
  6318. begin
  6319. is_objcclass:=
  6320. assigned(def) and
  6321. (def.typ=objectdef) and
  6322. (tobjectdef(def).objecttype=odt_objcclass);
  6323. end;
  6324. function is_objectpascal_helper(def: tdef): boolean;
  6325. begin
  6326. result:=
  6327. assigned(def) and
  6328. (def.typ=objectdef) and
  6329. (tobjectdef(def).objecttype=odt_helper);
  6330. end;
  6331. function is_objcclassref(def: tdef): boolean;
  6332. begin
  6333. is_objcclassref:=
  6334. assigned(def) and
  6335. (def.typ=classrefdef) and
  6336. is_objcclass(tclassrefdef(def).pointeddef);
  6337. end;
  6338. function is_objcprotocol(def: tdef): boolean;
  6339. begin
  6340. result:=
  6341. assigned(def) and
  6342. (def.typ=objectdef) and
  6343. (tobjectdef(def).objecttype=odt_objcprotocol);
  6344. end;
  6345. function is_objccategory(def: tdef): boolean;
  6346. begin
  6347. result:=
  6348. assigned(def) and
  6349. (def.typ=objectdef) and
  6350. { if used as a forward type }
  6351. ((tobjectdef(def).objecttype=odt_objccategory) or
  6352. { if used as after it has been resolved }
  6353. ((tobjectdef(def).objecttype=odt_objcclass) and
  6354. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6355. end;
  6356. function is_objc_class_or_protocol(def: tdef): boolean;
  6357. begin
  6358. result:=
  6359. assigned(def) and
  6360. (def.typ=objectdef) and
  6361. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  6362. end;
  6363. function is_objc_protocol_or_category(def: tdef): boolean;
  6364. begin
  6365. result:=
  6366. assigned(def) and
  6367. (def.typ=objectdef) and
  6368. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  6369. ((tobjectdef(def).objecttype = odt_objcclass) and
  6370. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6371. end;
  6372. function is_classhelper(def: tdef): boolean;
  6373. begin
  6374. result:=
  6375. is_objectpascal_helper(def) or
  6376. is_objccategory(def);
  6377. end;
  6378. function is_class_or_interface(def: tdef): boolean;
  6379. begin
  6380. result:=
  6381. assigned(def) and
  6382. (def.typ=objectdef) and
  6383. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  6384. end;
  6385. function is_class_or_interface_or_objc(def: tdef): boolean;
  6386. begin
  6387. result:=
  6388. assigned(def) and
  6389. (def.typ=objectdef) and
  6390. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  6391. end;
  6392. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  6393. begin
  6394. result:=
  6395. assigned(def) and
  6396. (def.typ=objectdef) and
  6397. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6398. end;
  6399. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  6400. begin
  6401. result:=
  6402. assigned(def) and
  6403. (def.typ=objectdef) and
  6404. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6405. end;
  6406. function is_class_or_interface_or_object(def: tdef): boolean;
  6407. begin
  6408. result:=
  6409. assigned(def) and
  6410. (def.typ=objectdef) and
  6411. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  6412. end;
  6413. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  6414. begin
  6415. result:=
  6416. assigned(def) and
  6417. (def.typ=objectdef) and
  6418. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  6419. end;
  6420. function is_implicit_pointer_object_type(def: tdef): boolean;
  6421. begin
  6422. result:=
  6423. assigned(def) and
  6424. (((def.typ=objectdef) and
  6425. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  6426. ((target_info.system in systems_jvm) and
  6427. (def.typ=recorddef)));
  6428. end;
  6429. function is_class_or_object(def: tdef): boolean;
  6430. begin
  6431. result:=
  6432. assigned(def) and
  6433. (def.typ=objectdef) and
  6434. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  6435. end;
  6436. function is_record(def: tdef): boolean;
  6437. begin
  6438. result:=
  6439. assigned(def) and
  6440. (def.typ=recorddef);
  6441. end;
  6442. function is_javaclass(def: tdef): boolean;
  6443. begin
  6444. result:=
  6445. assigned(def) and
  6446. (def.typ=objectdef) and
  6447. (tobjectdef(def).objecttype=odt_javaclass);
  6448. end;
  6449. function is_javaclassref(def: tdef): boolean;
  6450. begin
  6451. is_javaclassref:=
  6452. assigned(def) and
  6453. (def.typ=classrefdef) and
  6454. is_javaclass(tclassrefdef(def).pointeddef);
  6455. end;
  6456. function is_javainterface(def: tdef): boolean;
  6457. begin
  6458. result:=
  6459. assigned(def) and
  6460. (def.typ=objectdef) and
  6461. (tobjectdef(def).objecttype=odt_interfacejava);
  6462. end;
  6463. function is_java_class_or_interface(def: tdef): boolean;
  6464. begin
  6465. result:=
  6466. assigned(def) and
  6467. (def.typ=objectdef) and
  6468. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  6469. end;
  6470. procedure loadobjctypes;
  6471. begin
  6472. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  6473. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  6474. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  6475. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  6476. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  6477. end;
  6478. procedure maybeloadcocoatypes;
  6479. var
  6480. tsym: ttypesym;
  6481. cocoaunit: string[15];
  6482. begin
  6483. if assigned(objc_fastenumeration) then
  6484. exit;
  6485. if not(target_info.system in [system_arm_darwin,system_i386_iphonesim]) then
  6486. cocoaunit:='COCOAALL'
  6487. else
  6488. cocoaunit:='IPHONEALL';
  6489. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  6490. if assigned(tsym) then
  6491. objc_fastenumeration:=tobjectdef(tsym.typedef)
  6492. else
  6493. objc_fastenumeration:=nil;
  6494. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  6495. if assigned(tsym) then
  6496. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  6497. else
  6498. objc_fastenumerationstate:=nil;
  6499. end;
  6500. function use_vectorfpu(def : tdef) : boolean;
  6501. begin
  6502. {$ifdef x86}
  6503. {$define use_vectorfpuimplemented}
  6504. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  6505. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  6506. {$endif x86}
  6507. {$ifdef arm}
  6508. {$define use_vectorfpuimplemented}
  6509. use_vectorfpu:=(current_settings.fputype in vfp_scalar);
  6510. {$endif arm}
  6511. {$ifndef use_vectorfpuimplemented}
  6512. use_vectorfpu:=false;
  6513. {$endif}
  6514. end;
  6515. function getpointerdef(def: tdef): tpointerdef;
  6516. var
  6517. res: PHashSetItem;
  6518. oldsymtablestack: tsymtablestack;
  6519. begin
  6520. if not assigned(current_module) then
  6521. internalerror(2011071101);
  6522. res:=current_module.ptrdefs.FindOrAdd(@def,sizeof(def));
  6523. if not assigned(res^.Data) then
  6524. begin
  6525. { since these pointerdefs can be reused anywhere in the current
  6526. unit, add them to the global/staticsymtable }
  6527. oldsymtablestack:=symtablestack;
  6528. { do not simply push/pop current_module.localsymtable, because
  6529. that can have side-effects (e.g., it removes helpers) }
  6530. symtablestack:=nil;
  6531. res^.Data:=tpointerdef.create(def);
  6532. if assigned(current_module.localsymtable) then
  6533. current_module.localsymtable.insertdef(tdef(res^.Data))
  6534. else
  6535. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6536. symtablestack:=oldsymtablestack;
  6537. end;
  6538. result:=tpointerdef(res^.Data);
  6539. end;
  6540. function getsingletonarraydef(def: tdef): tarraydef;
  6541. begin
  6542. result:=getarraydef(def,1);
  6543. end;
  6544. function getarraydef(def: tdef; elecount: asizeint): tarraydef;
  6545. var
  6546. res: PHashSetItem;
  6547. oldsymtablestack: tsymtablestack;
  6548. arrdesc: packed record
  6549. def: tdef;
  6550. elecount: asizeint;
  6551. end;
  6552. begin
  6553. if not assigned(current_module) then
  6554. internalerror(2011081301);
  6555. arrdesc.def:=def;
  6556. arrdesc.elecount:=elecount;
  6557. res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
  6558. if not assigned(res^.Data) then
  6559. begin
  6560. { since these arraydef can be reused anywhere in the current
  6561. unit, add them to the global/staticsymtable }
  6562. oldsymtablestack:=symtablestack;
  6563. symtablestack:=nil;
  6564. res^.Data:=tarraydef.create(0,elecount-1,ptrsinttype);
  6565. tarraydef(res^.Data).elementdef:=def;
  6566. if assigned(current_module.localsymtable) then
  6567. current_module.localsymtable.insertdef(tdef(res^.Data))
  6568. else
  6569. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6570. symtablestack:=oldsymtablestack;
  6571. end;
  6572. result:=tarraydef(res^.Data);
  6573. end;
  6574. end.