symdef.pas 238 KB

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