symdef.pas 240 KB

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