symdef.pas 238 KB

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