symdef.pas 243 KB

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