symdef.pas 278 KB

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