symdef.pas 238 KB

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