symdef.pas 239 KB

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