symdef.pas 242 KB

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