symdef.pas 244 KB

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