symdef.pas 238 KB

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