symdef.pas 239 KB

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