symdef.pas 241 KB

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