1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303 |
- ' Copyright (c) 2013-2023 Bruce A Henderson
- '
- ' Based on the public domain Monkey "trans" by Mark Sibly
- '
- ' This software is provided 'as-is', without any express or implied
- ' warranty. In no event will the authors be held liable for any damages
- ' arising from the use of this software.
- '
- ' Permission is granted to anyone to use this software for any purpose,
- ' including commercial applications, and to alter it and redistribute it
- ' freely, subject to the following restrictions:
- '
- ' 1. The origin of this software must not be misrepresented; you must not
- ' claim that you wrote the original software. If you use this software
- ' in a product, an acknowledgment in the product documentation would be
- ' appreciated but is not required.
- '
- ' 2. Altered source versions must be plainly marked as such, and must not be
- ' misrepresented as being the original software.
- '
- ' 3. This notice may not be removed or altered from any source
- ' distribution.
- '
- SuperStrict
- Import "parser.bmx"
- Type TCTranslator Extends TTranslator
- 'Field stringConstCount:Int
- Field prefix:String
-
- Field reserved_methods:String = ",New,Delete,ToString,Compare,SendMessage,_reserved1_,_reserved2_,_reserved3_,".ToLower()
-
- Method New()
- _trans = Self
- End Method
- Method TransSPointer$( ty:TType, withVar:Int = False )
- Local p:String
-
- If ty
- If withVar And (ty._flags & TType.T_VAR) Then
- p:+ "*"
- End If
- If ty._flags & TType.T_PTR Then
- p:+ "*"
- Else If ty._flags & TType.T_PTRPTR Then
- p:+ "**"
- Else If ty._flags & TType.T_PTRPTRPTR Then
- p:+ "***"
- End If
- End If
-
- Return p
- End Method
- Method TransArrayType$( ty:TType)
- Local p:String = TransSPointer(ty)
-
- If TBoolType( ty ) Return "~q" + p + "i~q"
- If TByteType( ty ) Return "~q" + p + "b~q"
- If TShortType( ty ) Return "~q" + p + "s~q"
- If TIntType( ty ) Return "~q" + p + "i~q"
- If TUIntType( ty ) Return "~q" + p + "u~q"
- If TFloatType( ty ) Return "~q" + p + "f~q"
- If TDoubleType( ty ) Return "~q" + p + "d~q"
- If TLongType( ty ) Return "~q" + p + "l~q"
- If TULongType( ty ) Return "~q" + p + "y~q"
- If TLongIntType( ty ) Return "~q" + p + "v~q"
- If TULongIntType( ty ) Return "~q" + p + "e~q"
- If TSizeTType( ty ) Return "~q" + p + "z~q"
- If TWParamType( ty ) Return "~q" + p + "w~q"
- If TLParamType( ty ) Return "~q" + p + "x~q"
- If TStringType( ty ) Return "~q$~q"
- If TInt128Type( ty ) Return "~q" + p + "j~q"
- If TFloat128Type( ty ) Return "~q" + p + "k~q"
- If TDouble128Type( ty ) Return "~q" + p + "m~q"
- If TFloat64Type( ty ) Return "~q" + p + "h~q"
- If TArrayType( ty ) Then
- Local s:String = "["
- For Local i:Int = 0 Until TArrayType( ty ).dims - 1
- s:+ ","
- Next
- s:+ "]"
- s:+ TransArrayType(TArrayType( ty ).elemType)
- Return Enquote(s.Replace("~q", ""))
- End If
- If TObjectType( ty ) Then
- If TObjectType( ty ).classdecl.IsStruct()
- Return "~q" + p + "@" + TObjectType(ty).classDecl.ident + "~q"
- Else
- If Not TObjectType( ty ).classdecl.IsExtern()
- Return "~q:" + TObjectType(ty).classDecl.ident + "~q"
- Else
- If TObjectType( ty ).classdecl.IsInterface() Then
- Return "~q" + p + "*#" + TObjectType(ty).classDecl.ident + "~q"
- ' ElseIf TObjectType( ty ).classdecl.IsStruct()
- ' Return "~q" + p + "@" + TObjectType(ty).classDecl.ident + "~q"
- Else
- Return "~q" + p + "#" + TObjectType(ty).classDecl.ident + "~q"
- End If
- End If
- End If
- End If
- If TFunctionPtrType( ty ) Return "~q(~q"
- If TEnumType( ty ) Return "~q/" + TEnumType(ty).decl.ident + "~q"
- End Method
- Method TransDefDataType$( ty:TType)
- If TByteType( ty ) Return "~qb~q"
- If TShortType( ty ) Return "~qs~q"
- If TIntType( ty ) Return "~qi~q"
- If TUIntType( ty ) Return "~qu~q"
- If TFloatType( ty ) Return "~qf~q"
- If TDoubleType( ty ) Return "~qd~q"
- If TLongType( ty ) Return "~ql~q"
- If TULongType( ty ) Return "~qy~q"
- If TSizeTType( ty ) Return "~qz~q"
- If TLongIntType( ty ) Return "~qv~q"
- If TULongIntType( ty ) Return "~qe~q"
- If TStringType( ty ) Return "~q$~q"
- If TWParamType( ty ) Return "~qw~q"
- If TLParamType( ty ) Return "~qx~q"
- End Method
- Method TransDefDataConversion$(ty:TType)
- If TByteType( ty ) Return "bbConvertToInt"
- If TShortType( ty ) Return "bbConvertToInt"
- If TIntType( ty ) Return "bbConvertToInt"
- If TUIntType( ty ) Return "bbConvertToUInt"
- If TFloatType( ty ) Return "bbConvertToFloat"
- If TDoubleType( ty ) Return "bbConvertToDouble"
- If TLongType( ty ) Return "bbConvertToLong"
- If TULongType( ty ) Return "bbConvertToULong"
- If TSizeTType( ty ) Return "bbConvertToSizet"
- If TLongIntType( ty ) Return "bbConvertToLongInt"
- If TULongIntType( ty ) Return "bbConvertToULongInt"
- If TStringType( ty ) Return "bbConvertToString"
- End Method
- Method TransDefDataUnionType$(ty:TType)
- If TByteType( ty ) Return "b"
- If TShortType( ty ) Return "s"
- If TIntType( ty ) Return "i"
- If TUIntType( ty ) Return "u"
- If TFloatType( ty ) Return "f"
- If TDoubleType( ty ) Return "d"
- If TLongType( ty ) Return "l"
- If TULongType( ty ) Return "y"
- If TSizeTType( ty ) Return "z"
- If TLongIntType( ty ) Return "v"
- If TULongIntType( ty ) Return "e"
- If TWParamType( ty ) Return "w"
- If TLParamType( ty ) Return "x"
- If TStringType( ty ) Return "t"
- End Method
-
- Method TransDebugScopeType$(ty:TType)
- Local p:String = TransSPointer(ty)
- If TByteType( ty ) Return p + "b"
- If TShortType( ty ) Return p + "s"
- If TIntType( ty ) Return p + "i"
- If TUIntType( ty ) Return p + "u"
- If TFloatType( ty ) Return p + "f"
- If TDoubleType( ty ) Return p + "d"
- If TLongType( ty ) Return p + "l"
- If TULongType( ty ) Return p + "y"
- If TSizeTType( ty ) Return p + "t"
- If TLongIntType( ty ) Return p + "v"
- If TULongIntType( ty ) Return p + "e"
- If TWParamType( ty ) Return p + "W"
- If TLParamType( ty ) Return p + "X"
- If TInt128Type( ty ) Return p + "j"
- If TFloat128Type( ty ) Return p + "k"
- If TDouble128Type( ty ) Return p + "m"
- If TFloat64Type( ty ) Return p + "h"
- If TStringType( ty ) Return "$"
- If TArrayType( ty ) Then
- Local s:String = "["
- If TArrayType( ty ).isStatic Then
- s :+ TArrayType( ty ).length
- Else
- For Local i:Int = 0 Until TArrayType( ty ).dims - 1
- s:+ ","
- Next
- End If
- s:+ "]"
- Return s + TransDebugScopeType(TArrayType( ty ).elemType)
- End If
- If TObjectType( ty ) Then
- If TObjectType( ty ).classdecl.IsStruct() Then
- Return p + "@" + TObjectType(ty).classDecl.ident
- Else If Not TObjectType( ty ).classdecl.IsExtern()
- Return ":" + TObjectType( ty ).classDecl.ident
- Else
- If TObjectType( ty ).classdecl.IsInterface() Then
- Return p + "*#" + TObjectType(ty).classDecl.ident
- Else
- Return p + "#" + TObjectType(ty).classDecl.ident
- End If
- End If
- End If
- If TFunctionPtrType( ty ) Then
- Local func:TFuncDecl = TFunctionPtrType( ty ).func
- Local s:String = "("
- For Local i:Int = 0 Until func.argDecls.length
- If i Then
- s :+ ","
- End If
- s :+ TransDebugScopeType(func.argDecls[i].ty)
- Next
- Return s + ")" + TransDebugScopeType(func.retType)
- End If
- If TEnumType( ty ) Then
- Return "/" + TEnumType( ty ).decl.ident
- End If
- End Method
- Method TransType$( ty:TType, ident:String, fpReturnTypeFunctionArgs:String = Null, fpReturnTypeClassFunc:Int = False)
- Local p:String = TransSPointer(ty, True)
-
- If TVoidType( ty ) Or Not ty Then
- Return "void"
- End If
- If TBoolType( ty ) Return "BBINT" + p
- If TByteType( ty ) Return "BBBYTE" + p
- If TShortType( ty ) Return "BBSHORT" + p
- If TIntType( ty ) Return "BBINT" + p
- If TUIntType( ty ) Return "BBUINT" + p
- If TFloatType( ty ) Return "BBFLOAT" + p
- If TDoubleType( ty ) Return "BBDOUBLE" + p
- If TLongType( ty ) Return "BBLONG" + p
- If TULongType( ty ) Return "BBULONG" + p
- If TSizeTType( ty ) Return "BBSIZET" + p
- If TLongIntType( ty ) Return "BBLONGINT" + p
- If TULongIntType( ty ) Return "BBULONGINT" + p
- If TWParamType( ty ) Return "WPARAM" + p
- If TLParamType( ty ) Return "LPARAM" + p
- If TInt128Type( ty ) Return "BBINT128" + p
- If TFloat128Type( ty ) Return "BBFLOAT128" + p
- If TDouble128Type( ty ) Return "BBDOUBLE128" + p
- If TFloat64Type( ty ) Return "BBFLOAT64" + p
- If TStringType( ty ) Then
- If ty._flags & TType.T_CHAR_PTR Then
- Return "BBBYTE *"
- Else If ty._flags & TType.T_SHORT_PTR Then
- Return "BBSHORT *"
- End If
- Return "BBSTRING" + p
- End If
- If TArrayType( ty ) Then
- If TArrayType( ty ).isStatic Then
- Return TransType(TArrayType( ty ).elemType, ident)
- Else
- Return "BBARRAY" + p
- End If
- End If
- If TObjectType( ty ) Then
- Return TransObject(TObjectType(ty).classdecl) + p
- End If
- If TFunctionPtrType( ty ) Then
- TFunctionPtrType(ty).func.Semant
- Local api:String
- If TFunctionPtrType(ty).func.attrs & DECL_API_STDCALL Then
- api = " __stdcall "
- End If
- Local args:String
- For Local arg:TArgDecl = EachIn TFunctionPtrType(ty).func.argDecls
- arg.Semant()
- If args Then
- args :+ ","
- End If
- args :+ TransType(arg.ty, "")
- Next
- Local ret:String = ""
- If fpReturnTypeFunctionArgs Then
- ret = Bra(fpReturnTypeFunctionArgs)
- End If
-
- If fpReturnTypeClassFunc Then
- ' typedef for function pointer return type
- Return ident + "x" + Bra(api + p +"* " + ident) + Bra(args)
- Else
- ' if a function F returns another function (let's call it G),
- ' then C syntax requires the declaration of F to be nested into that of the type of G
- ' e.g. "Function F:RetG(ArgG)(ArgF)" in BlitzMax becomes "RetG(* F(ArgF) )(ArgG)" in C
- ' solution: use "* F(ArgF)" as an ident to generate a declaration for G
- ' the result will be the declaration for F
- Local callable:String = Bra(api + p +"* " + ident + ret)
- If TFunctionPtrType(TFunctionPtrType(ty).func.retType) Then
- If Not args Then args = " " ' make sure the parentheses aren't ommited even if the parameter list is empty
- Return TransType(TFunctionPtrType(ty).func.retType, callable, args)
- Else
- Local retTypeStr:String = TransType(TFunctionPtrType(ty).func.retType, "")
- Return retTypeStr + callable + Bra(args)
- End If
- End If
- End If
- If TExternObjectType( ty ) Return "struct " + TExternObjectType( ty ).classDecl.munged + p
- If TEnumType( ty ) Return TransType( TEnumType( ty ).decl.ty, ident ) + p
- InternalErr "TCTranslator.TransType"
- End Method
- Method TransIfcType$( ty:TType, isSuperStrict:Int = False )
- Local p:String = TransSPointer(ty)
- If ty And (ty._flags & TType.T_VAR) Then
- p :+ " Var"
- End If
-
- If Not ty Then
- If opt_issuperstrict Or isSuperStrict Then
- Return p
- Else
- Return "%" + p
- End If
- End If
- If TVoidType( ty ) Then
- Return p
- End If
- If TByteType( ty ) Return "@" + p
- If TShortType( ty ) Return "@@" + p
- If TIntType( ty ) Return "%" + p
- If TUIntType( ty ) Return "|" + p
- If TFloatType( ty ) Return "#" + p
- If TDoubleType( ty ) Return "!" + p
- If TLongType( ty ) Return "%%" + p
- If TULongType( ty ) Return "||" + p
- If TSizeTType( ty ) Return "%z" + p
- If TLongIntType( ty ) Return "%v" + p
- If TULongIntType( ty ) Return "%e" + p
- If TWParamType( ty ) Return "%w" + p
- If TLParamType( ty ) Return "%x" + p
- If TInt128Type( ty ) Return "%j" + p
- If TFloat128Type( ty ) Return "!k" + p
- If TDouble128Type( ty ) Return "!m" + p
- If TFloat64Type( ty ) Return "!h" + p
- If TStringType( ty ) Then
- If ty._flags & TType.T_CHAR_PTR Then
- Return "$z"
- Else If ty._flags & TType.T_SHORT_PTR Then
- Return "$w"
- End If
- Return "$" + p
- End If
- If TArrayType( ty ) Then
- Local s:String = TransIfcType(TArrayType( ty ).elemType) + "&["
- If TArrayType( ty ).isStatic Then
- s :+ TArrayType( ty ).length
- Else
- For Local i:Int = 0 Until TArrayType( ty ).dims - 1
- s:+ ","
- Next
- End If
- Return s + "]" + p
- End If
- If TObjectType( ty ) Then
- Local t:String = ":"
- If TObjectType(ty).classDecl.IsExtern() Then
- If TObjectType(ty).classDecl.IsInterface() Then
- t = "??"
- ElseIf TObjectType(ty).classDecl.IsStruct() Then
- t = "~~"
- Else
- t = "?"
- End If
- End If
- Local cdecl:TClassDecl = TObjectType(ty).classDecl
- ' find first type in hierarchy that isn't private
- While cdecl.IsPrivate() And cdecl.superClass <> Null
- cdecl = cdecl.superClass
- Wend
-
- Local args:String
- If cdecl.instArgs And cdecl.instArgs.length Then
- args = "<"
- For Local i:Int = 0 Until cdecl.instArgs.length
- If i Then
- args :+ ","
- End If
-
- args :+ cdecl.instArgs[i].ToString()
- Next
- args :+ ">"
- End If
-
- Return t + cdecl.ident + args + p
- End If
- If TFunctionPtrType( ty ) Then
- Local t:String = TransIfcType(TFunctionPtrType(ty).func.retType, TFunctionPtrType(ty).func.ModuleScope().IsSuperStrict()) + TransIfcArgs(TFunctionPtrType(ty).func)
- If TFunctionPtrType( ty ).func.attrs & DECL_API_STDCALL Then
- t :+ "W"
- End If
-
- Return t
- End If
- If TExternObjectType( ty ) Return ":" + TExternObjectType(ty).classDecl.ident + p
- If TEnumType( ty ) Then
- Return "/" + TEnumType( ty ).decl.ident + p
- End If
- InternalErr "TCTranslator.TransIfcType"
- End Method
- Method TransRefType$( ty:TType, ident:String )
- Return TransType( ty, ident )
- End Method
- Method TransValue$( ty:TType,value$, isStructInit:Int = False )
- If value
- If IsPointerType(ty, 0, TType.T_POINTER) Return value
- If TBoolType( ty ) Return "1"
- If TShortType( ty ) Return value
- If TIntType( ty ) Return value
- If TUIntType( ty ) Return value+"U"
- If TLongType( ty ) Return value+"LL"
- If TULongType( ty ) Return value+"ULL"
- If TSizeTType( ty ) Return value
- If TLongIntType( ty ) Return value
- If TULongIntType( ty ) Return value
- If TWParamType( ty ) Return value
- If TLParamType( ty ) Return value
- If TInt128Type( ty ) Return value
- If TFloatType( ty ) Then
- If value = "nan" Or value.StartsWith("1.#IND0000") Then
- Return "bbPOSNANf"
- Else If value="-nan" Or value.StartsWith("-1.#IND0000") Then
- Return "bbNEGNANf"
- Else If value = "inf" Or value.StartsWith("1.#INF0000") Then
- Return "bbPOSINFf"
- Else If value = "-inf" Or value.StartsWith("-1.#INF0000") Then
- Return "bbNEGINFf"
- Else
- If value.ToLower().Find("e")>=0 Then
- Return value
- End If
- If value.Find(".") < 0 Then
- value :+ ".0"
- End If
- Return value+"f"
- End If
- End If
- If TDoubleType( ty ) Or TFloat128Type(ty) Or TDouble128Type(ty) Or TFloat64Type(ty) Then
- If value = "nan" Or value.StartsWith("1.#IND0000") Then
- Return "bbPOSNANd"
- Else If value="-nan" Or value.StartsWith("-1.#IND0000") Then
- Return "bbNEGNANd"
- Else If value = "inf" Or value.StartsWith("1.#INF0000") Then
- Return "bbPOSINFd"
- Else If value = "-inf" Or value.StartsWith("-1.#INF0000") Then
- Return "bbNEGINFd"
- Else
- If value.ToLower().Find("e") >=0 Then
- Return value
- End If
- If value.Find(".") < 0 Then
- value :+ ".0"
- End If
- Return value
- End If
- End If
- If TStringType( ty ) Return TransStringConst(value )
- If TByteType( ty ) Return value
- If TEnumType( ty ) Return value
- Else
- If TBoolType( ty ) Return "0"
- If TIntrinsicType( ty) Then
- If IsPointerType(ty, 0, TType.T_POINTER) Then
- Return "0"
- Else
- Return "{}"
- End If
- End If
- If TNumericType( ty ) Return "0" ' numeric and pointers
- If TStringType( ty ) Then
- If isStructInit Then
- Return "&bbEmptyString"
- Else
- Return Bra("&bbEmptyString")
- End If
- End If
- If TArrayType( ty ) Then
- If isStructInit Then
- If TArrayType( ty ).isStatic Then
- Local t:String = "{"
- Local count:Int = 0
- For Local i:Int = 0 Until Int(TArrayType( ty ).length)
- count :+ 1
- If i Then
- t :+ ","
- End If
- If count = 100 Then
- t :+ "~n"
- count = 0
- End If
- t :+ TransValue(TArrayType( ty ).elemType, "", True)
- Next
- Return t + "}"
- Else
- Return "&bbEmptyArray"
- End If
- Else
- Return Bra("&bbEmptyArray")
- End If
- End If
- If TObjectType( ty ) Then
- If TObjectType( ty ).classDecl.IsExtern() Or TObjectType( ty ).classDecl.IsStruct() Then
- If TObjectType( ty ).classDecl.IsInterface() Or IsPointerType(ty,0,TType.T_POINTER) Or (Not TObjectType( ty ).classDecl.IsStruct()) Then
- Return "0"
- Else
- If TObjectType( ty ).classDecl.IsStruct() Then
- Local t:String
- If Not isStructInit Then
- t = "((" + TransType(ty, "") + "){"
- Else
- t = "{"
- End If
- Local fields:Int
- For Local f:TFieldDecl = EachIn TObjectType( ty ).classDecl.Decls()
- If fields Then
- t :+ ","
- End If
- fields = True
-
- t :+ TransValue(f.ty, "", True)
- Next
- If Not isStructInit Then
- t :+ "})"
- Else
- t :+ "}"
- End If
- Return t
- Else
- Return "{}"
- End If
- End If
- Else
- If isStructInit Then
- Return "&bbNullObject"
- Else
- Return Bra(Bra(TransType(ty, "*")) + "&bbNullObject")
- End If
- End If
- End If
- If TFunctionPtrType( ty) Return Bra(TransType(ty, "")) + "(&brl_blitz_NullFunctionError)"
- If TEnumType( ty ) Then
- If TEnumType( ty ).decl.isFlags Then
- Return "0"
- Else
- Return TEnumType( ty ).decl.values[0].Value()
- End If
- End If
- EndIf
- InternalErr "TCTranslator.TransValue"
- End Method
-
- Method TransArgs$( args:TExpr[],decl:TFuncDecl, objParam:String = Null, objectNew:Int = False )
- 'If decl.ident="AddS" DebugStop
- Local t$
- If objParam And (decl.IsMethod() Or decl.isCtor()) And ((Not decl.IsExtern()) Or (decl.IsExtern() And TClassDecl(decl.scope) And Not TClassDecl(decl.scope).IsStruct())) Then
- ' object cast to match param type
- If objectNew Then
- t :+ Bra("BBClass *")
- Else
- If TClassDecl(decl.scope) Then
- t :+ Bra(TransObject(TClassDecl(decl.scope).GetLatestFuncDecl(decl).scope, TClassDecl(decl.scope).IsStruct()))
- End If
- End If
- t:+ objParam
- End If
- For Local i:Int=0 Until decl.argDecls.Length
- Local argDecl:TArgDecl = decl.argDecls[i]
- Local ty:TType = TArgDecl(argDecl.actual).ty
-
- If t t:+","
- If i < args.length
- Local arg:TExpr = args[i]
-
- ' object cast to match param type
- If TObjectType(ty) And Not TObjectType(ty).classDecl.IsStruct() And Not argDecl.castTo Then
- Local fdecl:TFuncDecl = decl
- If TClassDecl(decl.scope) Then
- fdecl = TClassDecl(decl.scope).GetOriginalFuncDecl(decl)
- End If
- t :+ Bra(TransObject(TObjectType(TArgDecl(fdecl.argDecls[i].actual).ty).classDecl))
- End If
-
- Local varRef:String
-
- If TNullExpr(arg) Then
- t :+ TransValue(ty, Null)
- Continue
- Else If TIndexExpr(arg) And (ty._flags & TType.T_VAR)Then
- varRef = "&"
- Else If TStringType(ty) And (ty._flags & TType.T_VAR) Then
- If TCastExpr(arg) And TStringType(TCastExpr(arg).expr.exprType) Then
- varRef = "&"
- End If
- Else If TArrayType(ty) And (ty._flags & TType.T_VAR) Then
- If (TVarExpr(arg) And TArrayType(TVarExpr(arg).exprType) Or (TMemberVarExpr(arg) And TArrayType(TMemberVarExpr(arg).exprType))) And Not (arg.exprType._flags & TType.T_VAR) Then
- varRef = "&"
- End If
- Else If TObjectType(ty) And (ty._flags & TType.T_VAR) Then
- If (TVarExpr(arg) Or TMemberVarExpr(arg)) And TObjectType(arg.exprType) And Not (arg.exprType._flags & TType.T_VAR) Then
- varRef = "&"
- End If
- Else If TFunctionPtrType(ty) Or IsPointerType(ty, TType.T_BYTE) Then
- If TFunctionPtrType(ty) And (ty._flags & TType.T_VAR) Then
- varRef = "&"
- End If
- If TInvokeExpr(arg) And Not TInvokeExpr(arg).decl.IsMethod() Then
- t :+ varRef
- If IsPointerType(ty, TType.T_BYTE) Then
- t:+ TInvokeExpr(arg).Trans()
- Else
- ' need to test scopes to see if we need to use the current instance's function or not
- ' use the "actual", not the copy we made for the function pointer.
- Local fdecl:TFuncDecl = TFuncDecl(TInvokeExpr(arg).decl.actual)
- If Not fdecl.munged Then
- MungDecl fdecl
- TInvokeExpr(arg).decl.munged = fdecl.munged
- End If
- If TClassDecl(fdecl.scope) Then
- ' current scope is related to function scope?
- If _env.ClassScope() And _env.FuncScope() And _env.FuncScope().IsMethod() Then
- If _env.ClassScope().ExtendsClass(TClassDecl(fdecl.scope)) Then
- Local scope:TScopeDecl = _env.scope
- Local obj:String = Bra("struct " + scope.munged + "_obj*")
- Local class:String = "o->clas"
-
- t:+ class + "->f_" + fdecl.ident + MangleMethod(fdecl)
- Else
- t:+ fdecl.munged
- End If
- Else
- t:+ fdecl.munged
- End If
- Else
- t:+ fdecl.munged
- End If
- End If
- Continue
- End If
- ' some cases where we are passing a function pointer via a void* parameter.
- If TCastExpr(arg) And TInvokeExpr(TCastExpr(arg).expr) And Not TInvokeExpr(TCastExpr(arg).expr).invokedWithBraces Then
- t:+ varRef
- If Not TInvokeExpr(TCastExpr(arg).expr).decl.munged Then
- t:+ TInvokeExpr(TCastExpr(arg).expr).decl.actual.munged
- Else
- t:+ TInvokeExpr(TCastExpr(arg).expr).decl.munged
- End If
- Continue
- End If
- If TCastExpr(arg) And TVarExpr(TCastExpr(arg).expr) Then
- t:+ varRef
- t:+ TransCast(TFunctionPtrType(ty)) + Bra(arg.Trans())
- Continue
- End If
- ' Object -> Byte Ptr
- If IsPointerType(ty, TType.T_BYTE) And TObjectType(arg.exprType) Then
- t:+ varRef + Bra("bbObjectToFieldOffset" + Bra("(BBObject*)" + arg.Trans()))
- Continue
- End If
- Else If IsNumericType(ty) Then
- If TObjectType(arg.exprType) 'And TObjectType(args[i].exprType).classDecl = TClassDecl.nullObjectClass Then
- err "NULL"
- t:+ "0"
- Continue
- End If
- Else If TEnumType(ty) And (ty._flags & TType.T_VAR) Then
- If (TVarExpr(arg) Or TMemberVarExpr(arg)) And TEnumType(arg.exprType) And Not (arg.exprType._flags & TType.T_VAR) Then
- varRef = "&"
- End If
- End If
-
- If argDecl.castTo Then
- If argDecl.castTo.Find("*") >= 0 Then
- t:+ Bra(argDecl.castTo) + varRef + arg.Trans()
- Else
- t:+ varRef + Bra(argDecl.castTo) + arg.Trans()
- End If
- Else
- t :+ varRef
- Local tc:String = TransTemplateCast( ty,arg.exprType,arg.Trans() )
-
- ' *sigh*
- ' if var is going to var, remove any leading dereference character.
- ' rather hacky. Would be better to cast variable to varptr during semanting (well done if you can work out where!)
- If arg.exprType.EqualsType( ty.ActualType() ) And (ty._flags & TType.T_VAR) And ( (arg.exprType._flags & TType.T_VAR) Or (TSelfExpr(arg) And TObjectType(arg.exprType) And TObjectType(arg.exprType).classdecl.IsStruct())) Then
- If tc.startswith("*") Then
- tc = tc[1..]
- End If
- End If
- t:+ tc
-
- 't:+TransTemplateCast( ty,args[i].exprType,args[i].Trans() )
- End If
- Else
- argDecl.Semant()
- ' default values
- Local init:TExpr = argDecl.init
- If init Then
- If TConstExpr(init) Then
- If TObjectType(TConstExpr(init).exprType) Then
- t:+"NULLNULLNULL"
- ' And TNullDecl(TObjectType(TConstExpr(init).exprType).classDecl)) Or (TConstExpr(init).value = "bbNullObject") Then
- If TStringType(argDecl.ty) Then
- t :+ "&bbEmptyString"
- Else If TArrayType(argDecl.ty) Then
- t :+ "&bbEmptyArray"
- Else
- t :+ "&bbNullObject"
- End If
- Else
- t:+ argDecl.init.Trans()
- End If
- Else If TFunctionPtrType(ty) Then
- If TInvokeExpr(init) Then
- t:+ TInvokeExpr(init).decl.munged
- End If
- Else
- t:+ argDecl.init.Trans()
- End If
- End If
- End If
- Next
- Return Bra(t)
- End Method
- ' translate to C cast
- Method TransCast:String(funcPtr:TFunctionPtrType)
- If Not funcPtr Then
- Return ""
- End If
- Local s:String = "("
- s:+ TransType(funcPtr.func.retType, "")
- s:+ "(*)("
- For Local i:Int=0 Until funcPtr.func.argDecls.Length
- If i Then
- s:+ ","
- End If
- s:+ TransType(funcPtr.func.argDecls[i].ty, "")
- Next
- s:+ ")"
- s:+ ")"
- Return s
- End Method
- Method TransArgsTypes$( args:TExpr[],declArgTypes:TType[])
- Local t$
- For Local i:Int=0 Until args.Length
- If t t:+","
- t:+TransTemplateCast( declArgTypes[i],args[i].exprType,args[i].Trans() )
- Next
- Return Bra(t)
- End Method
- Method TransPtrCast$( ty:TType,src:TType,expr$,cast$ )
- If IsPointerType(ty, 0, TType.T_POINTER | TType.T_VARPTR | TType.T_VAR) Or TFunctionPtrType(ty) Then
- ' TODO : pointer stuff
- If TNullType(src) Return TransValue(ty, Null)
- Return expr
- End If
- 'If expr = "NULL" DebugStop
- ' If TIntType(ty) And TStringType(src) Then
- 'DebugStop
- ' Return "bbObjectDowncast" + Bra(expr + ",&" + TStringType(src).cDecl.munged)
- ' End If
- If TNullType(src)
- Return TransValue(ty, Null)
- End If
- If TStringType(ty) And TObjectType(src) Then
- If Not TStringType(ty).cDecl Then
- ty.Semant()
- End If
- 'If TNullDecl(TObjectType(src).classDecl) Then
- ' Return "&bbEmptyString"
- 'End If
- Return Bra("(BBString *)bbObjectStringcast" + Bra("(BBOBJECT)" + expr ))
- End If
- 'If TArrayType(ty) And TObjectType(src) Then
- ' If TNullDecl(TObjectType(src).classDecl) Then
- ' Return "&bbEmptyArray"
- ' End If
- 'End If
- If TVarPtrType(src) And TNumericType(ty) Then
- Return "*" + expr
- End If
- If TIntType(ty) And TStringType(src) Then
- Return Bra(expr + " != &bbEmptyString")
- End If
- ' If TIntType(ty) And TObjectType(src) Then
- ' Return Bra(expr + " != &bbNullObject")
- ' End If
- If TObjectType(ty) And TStringType(src) Then
- Return expr
- End If
- If Not TObjectType(ty) Or Not TObjectType(src) Then
- InternalErr "TCTranslator.TransPtrCast"
- End If
- Local t$=TransType(ty, "TODO: TransPtrCast")
- If src.GetClass().IsInterface() Or ty.GetClass().IsInterface() cast="dynamic"
- If src.GetClass().IsInterface() And Not ty.GetClass().IsInterface() Then
- Return cast+"_cast<"+TransType(ty, "TODO: TransPtrCast")+">"+Bra( expr )
- End If
- 'upcast?
- If src.GetClass().ExtendsClass( ty.GetClass() ) Return expr
- If TObjectType(ty) Then
- Return Bra(Bra(TransObject(TObjectType(ty).classDecl)) + "bbObjectDowncast" + Bra("(BBOBJECT)" + expr + ",(BBClass*)&" + TObjectType(ty).classDecl.munged))
- End If
- Return cast+"_cast<"+TransType(ty, "TODO: TransPtrCast")+">"+Bra( expr )
- End Method
- '***** Utility *****
- Method TransLocalDecl$( decl:TLocalDecl,init:TExpr, declare:Int = False, outputInit:Int = True )
- Local initTrans:String
- If outputInit Then
- Local cast:String
- If (TObjectType(decl.ty) And Not TObjectType(decl.ty).classDecl.IsStruct()) Or TFunctionPtrType(decl.ty) Then
- cast = Bra(TransType(decl.ty, ""))
- End If
-
- If TInvokeExpr(init) And Not TInvokeExpr(init).invokedWithBraces Then
- initTrans = "=" + cast + TInvokeExpr(init).decl.munged
- Else
- If Not TArrayType(decl.ty) Or Not TArrayType(decl.ty).isStatic Then
- initTrans = "=" + cast + init.Trans()
- Else
- initTrans = "[" + TArrayType(decl.ty).length + "]=" + TransValue(decl.ty, Null, True)
- End If
- End If
- End If
-
- Local volTrans:String = " "
- If decl.volatile Then
- volTrans = " volatile "
- End If
-
- If Not declare And opt_debug Then
- Local ty:TType = decl.ty
- If Not TObjectType( ty ) Or (TObjectType( ty ) And Not TObjectType( ty ).classDecl.IsStruct()) Then
- If TIntrinsicType(ty) Then
- If Not TConstExpr(init) Then
- Return decl.munged + initTrans
- End If
- Else If Not TArrayType(ty) Or Not TArrayType(ty).isStatic Then
- Return decl.munged + initTrans
- End If
- Else If TObjectType( ty ) And TObjectType( ty ).classDecl.IsStruct() Then
- If Not TConstExpr(init) Then
- Return decl.munged + initTrans
- End If
- End If
- Else
- If TFunctionPtrType(decl.ty) Then
- If TInvokeExpr(init) And Not TInvokeExpr(init).invokedWithBraces Then
- Return TransType( decl.ty, decl.munged ) + " = " + TInvokeExpr(init).decl.munged
- Else
- Return TransType( decl.ty, decl.munged ) + initTrans
- End If
- Else
- Local ty:TType = decl.ty
- If TVoidType( ty ) Or Not ty Then
- ty = init.exprType
- End If
- If TObjectType(ty) Then
- If TObjectType(ty).classdecl.IsExtern() Then
- If TObjectType(ty).classdecl.IsInterface() Then
- Return TransType( ty, decl.munged )+" "+decl.munged + initTrans
- Else
- Return TransType( ty, decl.munged )+ volTrans +decl.munged + initTrans
- End If
- Else
- If TObjectType(ty).classdecl.IsStruct() Then
- Return TransType( ty, decl.munged )+" "+decl.munged + initTrans
- Else
- 'If decl.volatile Then
- Return TransType( ty, decl.munged )+ volTrans +decl.munged + initTrans
- 'Else
- ' Return TransType( ty, decl.munged )+" "+decl.munged + initTrans
- 'End If
- End If
- End If
- Else
- Return TransType( ty, decl.munged )+ volTrans +decl.munged + initTrans
- End If
- End If
- End If
- End Method
- Method TransLocalDeclNoInit$( decl:TVarDecl )
- If TFunctionPtrType(decl.ty) Then
- Return TransType( decl.ty, decl.munged ) + "=" + TransValue(decl.ty, "")
- Else
- If TObjectType(decl.ty) Then
- If TObjectType(decl.ty).classdecl.IsExtern() Then
- If Not TObjectType(decl.ty).classdecl.IsStruct() Then
- Return TransType( decl.ty, decl.munged )+" "+decl.munged+"=" + TransValue(decl.ty, "")
- Else
- Return TransType( decl.ty, decl.munged )+" "+decl.munged
- End If
- Else
- If Not TObjectType(decl.ty).classdecl.IsStruct() Then
- Local cast:String = Bra(TransObject(TObjectType(decl.ty).classDecl))
-
- If TLocalDecl(decl) And TLocalDecl(decl).volatile Then
- Return TransType( decl.ty, decl.munged )+" volatile "+decl.munged + "=" + cast + TransValue(decl.ty, "")
- Else
- Return TransType( decl.ty, decl.munged )+" "+decl.munged + "=" + cast + TransValue(decl.ty, "")
- End If
- Else
- Return TransType( decl.ty, decl.munged )+" "+decl.munged + "=" + TransValue(decl.ty, "")
- End If
- End If
- Else
- If TLocalDecl(decl) And TLocalDecl(decl).volatile Then
- Return TransType( decl.ty, decl.munged )+" volatile "+decl.munged + "=" + TransValue(decl.ty, "")
- Else
- If TArrayType(decl.ty) And TArrayType(decl.ty).isStatic Then
- Local t:String = TransType( decl.ty, decl.munged )+" "+decl.munged + "[" + TArrayType(decl.ty).length + "]"
- t :+ "={"
- Local count:Int
- For Local i:Int = 0 Until Int(TArrayType( decl.ty ).length)
- count :+ 1
- If i Then
- t :+ ","
- End If
- If count = 100 Then
- t :+ "~n"
- count = 0
- End If
- t :+ TransValue(TArrayType( decl.ty ).elemType, "", True)
- Next
- Return t + "}"
- Else
- Return TransType( decl.ty, decl.munged )+" "+decl.munged + "=" + TransValue(decl.ty, "")
- End If
- End If
- End If
- End If
- End Method
- Method TransGlobalDecl$( gdecl:TGlobalDecl )
- Local glob:String
- If Not gdecl.funcGlobal Then
- If Not (gdecl.attrs & DECL_INITONLY) Then
- glob :+"static " + TransThreadedGlobal(gdecl) + TransType( gdecl.init.exprType, gdecl.munged )+" "
- End If
-
- glob :+ gdecl.munged+"="
-
- If (TNewObjectExpr(gdecl.init) Or TNewArrayExpr(gdecl.init)) And Not (gdecl.attrs & DECL_INITONLY) Then
- glob :+ "0;~n"
- glob :+ indent + "if (" + gdecl.munged + "==0) {~n"
- glob :+ indent + "~t" + gdecl.munged + "=" + gdecl.init.Trans() + ";~n"
- glob :+ indent + "}"
- Else If TArrayExpr(gdecl.init) And Not (gdecl.attrs & DECL_INITONLY) Then
- glob :+ "0;~n"
- Emit glob
- Emit "if (" + gdecl.munged + "==0) {"
-
- glob = gdecl.munged + "=" + gdecl.init.Trans() + ";"
- Emit glob
- Emit "}"
- glob = ""
- Else
- If gdecl.init Then
- If TFunctionPtrType(gdecl.ty) Then
- If TInvokeExpr(gdecl.init) And Not TInvokeExpr(gdecl.init).invokedWithBraces Then
- glob :+ TransCast(TFunctionPtrType(gdecl.ty)) + TInvokeExpr(gdecl.init).decl.munged
- Else
- glob :+ TransCast(TFunctionPtrType(gdecl.ty)) + gdecl.init.Trans()
- End If
- Else If Not TConstExpr(gdecl.init) And Not (gdecl.attrs & DECL_INITONLY) Then
- ' for non const, we need to add an initialiser
- glob :+ TransValue(gdecl.ty, "") + ";~n"
- glob :+ indent +"static " + TransThreadedGlobal(gdecl) + " int _" + gdecl.munged + "_inited = 0;~n"
- glob :+ indent + "if (!_" + gdecl.munged + "_inited) {~n"
- glob :+ indent + "~t_" + gdecl.munged + "_inited = 1;~n"
- glob :+ indent + "~t" + gdecl.munged + " = " + gdecl.init.Trans() + ";~n"
- glob :+ indent + "}"
- Else
- If TObjectType(gdecl.ty) Then
- glob :+ Bra(TransObject(TObjectType(gdecl.ty).classDecl))
- End If
- glob :+ gdecl.init.Trans()
- End If
- Else
- If TFunctionPtrType(gdecl.ty) Then
- glob :+ "&brl_blitz_NullFunctionError"
- Else
- glob :+ "0"
- End If
- End If
- End If
- Else
- glob :+ "static " + TransThreadedGlobal(gdecl) + " int _" + gdecl.munged + "_inited = 0;~n"
- glob :+ indent + "if (!_" + gdecl.munged + "_inited) {~n"
- glob :+ indent + "~t_" + gdecl.munged + "_inited = 1;~n"
- glob :+ indent + "~t" + gdecl.munged + " = "
- If gdecl.init Then
- glob :+ gdecl.init.Trans()
- Else
- glob :+ TransValue(gdecl.ty, "")
- End If
- glob :+ ";~n"
- glob :+ indent + "}"
- End If
- Return glob
- End Method
-
- Method TransExportDef:String(decl:TFuncDecl, withApi:Int = True)
- Local t:String = decl.munged
-
- If withApi And decl.attrs & DECL_API_STDCALL Then
- t :+ "@"
- Local size:Int
- For Local arg:TArgDecl = EachIn decl.argDecls
- size :+ arg.ty.GetSize()
- Next
- t :+ size
- End If
-
- Return t
- End Method
- Method CreateLocal2$( ty:TType, t$ )
- Local tmp:TLocalDecl=New TLocalDecl.Create( "", ty,Null, True )
- MungDecl tmp
- If TShortType(ty) Then
- Emit TransType(ty, "") + " " + tmp.munged + " = bbStringToWString" + Bra(t)+ ";"
- Else
- Emit TransType(ty, "") + " " + tmp.munged + " = (BBBYTE*)bbStringToCString" + Bra(t)+ ";"
- End If
- customVarStack.Push(tmp.munged)
- Return tmp.munged
- End Method
- Method EmitPushErr()
- Emit "pushErr();"
- End Method
- Method EmitSetErr( info$ )
- Emit "errInfo=~q"+info.Replace( "\","/" )+"~q;"
- End Method
- Method EmitPopErr()
- Emit "popErr();"
- End Method
- '***** Declarations *****
- Method TransStatic$( decl:TDecl )
- If decl.IsExtern() Then
- If Not decl.munged
- Return decl.ident
- End If
- Return decl.munged
- Else If _env And decl.scope And decl.scope=_env.ClassScope()
- ' calling a class function from a method?
- If TFuncDecl(decl) And _env.ClassScope() And _env.FuncScope() And _env.FuncScope().IsMethod() And Not (decl.attrs & FUNC_PTR) And Not _env.ClassScope().IsStruct() Then
- Local scope:TScopeDecl = _env.ClassScope()
- Local obj:String = Bra("struct " + scope.munged + "_obj*")
- Local class:String = "o->clas"
- Return class + "->f_" + decl.ident + MangleMethod(TFuncDecl(decl))
- Else
- Return decl.munged
- End If
- Else If TClassDecl( decl.scope )
- 'Return decl.scope.munged+"::"+decl.munged
- Return decl.munged
- Else If TModuleDecl( decl.scope )
- Return decl.munged
- Else If TFuncDecl(decl.scope)
- Return decl.munged
- Else If TGlobalDecl(decl)
- Return decl.munged
- Else If TBlockDecl(decl.scope)
- Return decl.munged
- Else If TEnumDecl(decl.scope)
- Select decl.ident
- Case "Values"
- Return "bbEnumValues"
- Default
- Return decl.munged
- End Select
- EndIf
- InternalErr "TCTranslator.TransStatic"
- End Method
-
- Method TransThreadedGlobal:String( decl:TDecl )
- If decl.attrs & DECL_THREADED Then
- Return "BBThreadLocal "
- Else
- Return ""
- End If
- End Method
- Method TransTemplateCast$( ty:TType,src:TType,expr$ )
- ' *sigh*
- ' if var is going to var, remove any leading dereference character.
- ' rather hacky. Would be better to cast variable to varptr during semanting (well done if you can work out where!)
- 'If src.EqualsType( ty.ActualType() ) And (ty._flags & TType.T_VAR) And (src._flags & TType.T_VAR) Then
- ' If expr.startswith("*") Then
- ' expr = expr[1..]
- ' End If
- 'End If
- If ty=src Return expr
- ty=ty.ActualType()
- 'src=src.ActualType()
- If src.EqualsType( ty ) Return expr
- Return TransPtrCast( ty,src,expr,"static" )
- End Method
- Method TransGlobal$( decl:TGlobalDecl )
- Return TransStatic( decl )
- End Method
- Method TransField$( decl:TFieldDecl,lhs:TExpr )
- If lhs Then
- Return TransFieldRef(decl, TransSubExpr( lhs ), lhs.exprType)
- Else
- Return TransFieldRef(decl, "o", Null)
- End If
- ' Local swiz$
- ' If TObjectType( decl.ty )
- ' If TObjectType( decl.ty ).classDecl.IsInterface() swiz=".p"
- ' EndIf
- ' If lhs Return TransSubExpr( lhs )+"->"+decl.munged+swiz
- ' Return decl.munged+swiz
- End Method
- Method TransFunc$( decl:TFuncDecl,args:TExpr[],lhs:TExpr, sup:Int = False, scope:TScopeDecl = Null )
- ' for calling the super class method instead
- Local tSuper:String
- If sup Then
- tSuper = "->super"
- End If
- If Not decl.munged
- MungDecl decl
- End If
- 'If decl.IsMethod()
- If lhs And Not TSelfExpr(lhs) Then
- If TStringType(lhs.exprType) Then
- Return decl.munged + TransArgs(args, decl, TransSubExpr( lhs ))
- End If
- If TStmtExpr(lhs) Then
- lhs.Trans()
- lhs = TStmtExpr(lhs).expr
- End If
- If TVarExpr(lhs) Then
- Local cdecl:TClassDecl
- If TObjectType(TVarExpr(lhs).decl.ty) Then
- cdecl = TObjectType(TVarExpr(lhs).decl.ty).classDecl
- Else If TArrayType(TVarExpr(lhs).decl.ty) Then
- Return decl.munged+TransArgs( args,decl, TransSubExpr( lhs ) )
- End If
- If decl.attrs & FUNC_PTR Then
- 'Return "(" + obj + TransSubExpr( lhs ) + ")->" + decl.munged+TransArgs( args,decl, Null)
- Local op:String
- If cdecl.IsStruct() Then op = "." Else op = "->"
- Return TransSubExpr( lhs ) + op + decl.munged+TransArgs( args,decl, Null)
- Else
- 'Local lvar:String = CreateLocal(lhs, False)
- 'Local lvarInit:String = Bra(lvar + " = " + lhs.Trans())
-
- If decl.scope.IsExtern()
- If Not cdecl.IsStruct() Then
- 'Return decl.munged + Bra(TransArgs( args,decl, TransSubExpr( lhs ) ))
- Return Bra(TransSubExpr( lhs )) + "->vtbl->" + decl.munged + Bra(TransArgs( args,decl, TransSubExpr( lhs ) ))
- 'Return Bra(lvarInit) + "->vtbl->" + decl.munged + Bra(TransArgs( args,decl, lvar ))
- End If
- Err "TODO extern types not allowed methods"
- Else
- If cdecl And cdecl.IsInterface() And Not equalsBuiltInFunc(cdecl, decl) Then
- Local ifc:String = Bra("(struct " + cdecl.munged + "_methods*)" + Bra("bbObjectInterface((BBObject*)" + TransSubExpr( lhs ) + ", " + "(BBInterface*)&" + cdecl.munged + "_ifc)"))
- Return ifc + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, TransSubExpr( lhs ) )
- ' Local ifc:String = Bra("(struct " + cdecl.munged + "_methods*)" + Bra("bbObjectInterface(" + lvarInit + ", " + "&" + cdecl.munged + "_ifc)"))
- ' Return ifc + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- Else
- If cdecl And cdecl.IsStruct() Then
- Local pref:String
- If decl.IsMethod() Then
- pref = "_"
- End If
- If Not isPointerType(lhs.exprType) Then
- Return pref + decl.munged+TransArgs( args,decl, "&" + TransSubExpr( lhs ) )
- Else
- Return pref + decl.munged+TransArgs( args,decl, TransSubExpr( lhs ) )
- End If
- Else
- If cdecl Then
- Local obj:String = TransSubExpr( lhs )
- Local preObj:String = obj
-
- If opt_debug Then
- preObj = TransDebugNullObjectError(obj, cdecl)
- End If
-
- Local class:String = Bra(preObj) + "->clas" + tSuper
- Return class + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, obj )
- Else
- If TEnumDecl(decl.scope) Then
- ' since we already have the ordinal, we can simply output that
- If decl.ident = "Ordinal" Then
- Return Bra(TransSubExpr( lhs ))
- Else
- Return decl.munged + Bra(TransSubExpr( lhs ))
- End If
- End If
- End If
- ' Local class:String = Bra(lvarInit) + "->clas" + tSuper
- ' Return class + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- End If
- End If
- End If
- End If
- Else If TNewObjectExpr(lhs) Then
- Local cdecl:TClassDecl = TNewObjectExpr(lhs).classDecl
- If cdecl.IsStruct() Then
- ' create a local variable of the inner invocation
- Local lvar:String = CreateLocal(lhs)
- Local t:String
- If decl.IsMethod() Then
- t = "_"
- End If
- Return t + decl.munged+TransArgs( args,decl, "&" + lvar )
- Else
- If decl.IsMethod() Then
- Local class:String = cdecl.munged
- Return class + "." + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, TransSubExpr( lhs ) )
- Else
- Local class:String = Bra(Bra("struct " + cdecl.munged + "_obj*") + Bra(TransSubExpr( lhs ))) + "->clas" + tSuper
- Return class + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl )
- End If
- End If
- Else If TCastExpr(lhs) Then
- Local ty:TType = TCastExpr(lhs).ty
- If TObjectType(ty) Then
- ' create a local variable of the inner invocation
- Local lvar:String = CreateLocal(lhs, False, False)
- Local lvarInit:String = Bra(lvar + " = " + lhs.Trans())
- Local cdecl:TClassDecl = TObjectType(ty).classDecl
- Local obj:String = Bra(TransObject(cdecl))
- If decl.attrs & FUNC_PTR Then
- Return "(" + obj + TransSubExpr( lhs ) + ")->" + decl.munged+TransArgs( args,decl, Null)
- Else
- ' Null test
- If opt_debug Then
- lvarInit = TransDebugNullObjectError(lvarInit, cdecl)
- End If
-
- If cdecl.IsInterface() And Not equalsBuiltInFunc(cdecl, decl) Then
- Local ifc:String = Bra("(struct " + cdecl.munged + "_methods*)" + Bra("bbObjectInterface((BBObject*)" + obj + lvarInit + ", " + "(BBInterface*)&" + cdecl.munged + "_ifc)"))
- Return ifc + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- Else
- Local class:String = Bra("(" + obj + lvarInit + ")->clas" + tSuper)
- Return class + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- End If
- End If
- Else If TEnumType(ty) Then
- If TEnumDecl(decl.scope) Then
- ' since we already have the ordinal, we can simply output that
- If decl.ident = "Ordinal" Then
- Return Bra(TransSubExpr( lhs ))
- Else
- Return decl.munged + Bra(TransSubExpr( lhs ))
- End If
- End If
- End If
- Else If TMemberVarExpr(lhs) Then
- If TObjectType(TMemberVarExpr(lhs).decl.ty) Then
- Local cdecl:TClassDecl = TObjectType(TMemberVarExpr(lhs).decl.ty).classDecl
- Local obj:String = Bra(TransObject(cdecl))
-
- If decl.scope.IsExtern()
- If TClassDecl(decl.scope) And Not TClassDecl(decl.scope).IsStruct() Then
- Local lvar:String = CreateLocal(lhs, False, False)
- Local lvarInit:String = Bra(lvar + " = " + lhs.Trans())
-
- Return Bra(lvarInit) + "->vtbl->" + decl.munged + Bra(TransArgs( args,decl, lvar ))
- Else
- Return decl.munged + Bra(TransArgs( args,decl, TransSubExpr( lhs ) ))
- End If
- Else
- If cdecl.IsStruct() Then
- Local pref:String
- If decl.IsMethod() Then
- pref = "_"
- End If
- If Not isPointerType(lhs.exprType) Then
- Return pref + decl.munged+TransArgs( args,decl, "&" + TransSubExpr( lhs ) )
- Else
- Return pref + decl.munged+TransArgs( args,decl, TransSubExpr( lhs ) )
- End If
-
- Else
- If decl.attrs & FUNC_PTR Then
- Return "(" + obj + TransSubExpr( lhs ) + ")->" + decl.munged+TransArgs( args,decl, Null)
- Else
- Local lvar:String = CreateLocal(lhs, False, False)
- Local lvarInit:String = Bra(lvar + " = " + lhs.Trans())
-
- ' Null test
- If opt_debug Then
- lvarInit = TransDebugNullObjectError(lvarInit, cdecl)
- End If
-
- If cdecl.IsInterface() And Not equalsBuiltInFunc(cdecl, decl) Then
- Local obj:String = Bra(TransObject(cdecl))
- Local ifc:String = Bra("(struct " + cdecl.munged + "_methods*)" + Bra("bbObjectInterface((BBObject*)" + obj + lvarInit + ", " + "(BBInterface*)&" + cdecl.munged + "_ifc)"))
- Return ifc + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- Else
- Local class:String = Bra("(" + obj + lvarInit + ")->clas" + tSuper)
- Return class + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- End If
- End If
- End If
- End If
-
- Else If TArrayType(TMemberVarExpr(lhs).decl.ty) Then
- Return decl.munged+TransArgs( args,decl, TransSubExpr( lhs ) )
- End If
- Else If TInvokeExpr(lhs) Then
- If TEnumType(lhs.exprType) Then
- If decl.ident = "Ordinal" Then
- Return Bra(TransSubExpr( lhs ))
- Else
- Return decl.munged + Bra(TransSubExpr( lhs ))
- End If
- End If
- If TClassDecl(decl.scope) And TClassDecl(decl.scope).IsStruct() Then
- ' create a local variable of the inner invocation
- Local lvar:String = CreateLocal(lhs, True)
- Local pref:String
- If decl.IsMethod() Then
- pref = "_"
- End If
- If Not isPointerType(lhs.exprType) Then
- Return pref + decl.munged+TransArgs( args,decl, "&" + lvar )
- Else
- Return pref + decl.munged+TransArgs( args,decl, lvar)
- End If
- Else
- ' create a local variable of the inner invocation
- Local lvar:String = CreateLocal(lhs, False, False)
- Local lvarInit:String = Bra(lvar + " = " + lhs.Trans())
- ' Null test
- If opt_debug Then
- Local cdecl:TClassDecl = TClassDecl(decl.scope)
- lvarInit = TransDebugNullObjectError(lvarInit, cdecl)
- End If
-
- Local obj:String = Bra(TransObject(decl.scope))
- Local class:String = Bra("(" + obj + lvarInit +")->clas" + tSuper)
- Return class + "->" + TransFuncPrefix(decl.scope, decl)+ FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- End If
- 'Local obj:String = Bra("struct " + decl.scope.munged + "_obj*")
- 'Local class:String = Bra("(" + obj + TransSubExpr( lhs ) +")->clas" + tSuper)
- 'Local class:String = Bra("&" + decl.scope.munged)
- 'Return class + "->" + TransFuncPrefix(decl.scope, decl.ident) + decl.ident+TransArgs( args,decl, TransSubExpr( lhs ) )
- Else If TInvokeMemberExpr(lhs)
- If TEnumType(lhs.exprType) Then
- If decl.ident = "Ordinal" Then
- Return Bra(TransSubExpr( lhs ))
- Else
- Return decl.munged + Bra(TransSubExpr( lhs ))
- End If
- End If
- ' create a local variable of the inner invocation
-
- Local lvar:String
- Local lvarInit:String
-
- If Not decl.scope.IsExtern() And TClassDecl(decl.scope) And TClassDecl(decl.scope).IsStruct() Then
- lvar = CreateLocal(lhs, True)
- Else
- lvar = CreateLocal(lhs, False, False)
- lvarInit = Bra(lvar + " = " + lhs.Trans())
- End If
- If decl.scope.IsExtern()
- If TClassDecl(decl.scope) And Not TClassDecl(decl.scope).IsStruct() Then
- Return Bra(lvarInit) + "->vtbl->" + decl.munged + Bra(TransArgs( args,decl, lvar ))
- End If
-
- Return "// TODO"
- Else
- If TClassDecl(decl.scope) And TClassDecl(decl.scope).IsStruct() Then
- If Not isPointerType(lhs.exprType) Then
- Return "_" + decl.munged+TransArgs( args,decl, "&" + lvar )
- Else
- Return "_" + decl.munged+TransArgs( args,decl, lvar )
- End If
- Else
- Local cdecl:TClassDecl = TClassDecl(decl.scope)
- ' Null test
- If opt_debug Then
- lvarInit = TransDebugNullObjectError(lvarInit, cdecl)
- End If
- If cdecl.IsInterface() And Not equalsBuiltInFunc(cdecl, decl) Then
- Local obj:String = Bra(TransObject(cdecl))
- Local ifc:String = Bra("(struct " + cdecl.munged + "_methods*)" + Bra("bbObjectInterface((BBObject*)" + obj + lvarInit + ", " + "(BBInterface*)&" + cdecl.munged + "_ifc)"))
- Return ifc + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- Else
- Local obj:String = lvarInit + "->clas" + tSuper
- Return obj + "->" + TransFuncPrefix(decl.scope, decl)+ FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- End If
- End If
- End If
- Else If TIndexExpr(lhs) Then
- If TEnumType(lhs.exprType) Then
- If decl.ident = "Ordinal" Then
- Return Bra(TransSubExpr( lhs ))
- Else
- Return decl.munged + Bra(TransSubExpr( lhs ))
- End If
- End If
-
- If TClassDecl(decl.scope) And TClassDecl(decl.scope).IsStruct() Then
-
- Local lvar:String = CreateLocal(lhs, True, False)
-
- Local pref:String
- If decl.IsMethod() Then
- pref = "_"
- End If
- If Not isPointerType(lhs.exprType) Then
- Return pref + decl.munged+TransArgs( args,decl, "&" + lvar )
- Else
- Return pref + decl.munged+TransArgs( args,decl, lvar )
- End If
- Else
- Local lvar:String = CreateLocal(lhs, False, False)
- Local lvarInit:String = Bra(lvar + " = " + lhs.Trans())
-
- ' Local loc:String = CreateLocal(lhs)
- Local obj:String = Bra(TransObject(decl.scope))
-
- Local cdecl:TClassDecl = TClassDecl(decl.scope)
-
- ' Null test
- If opt_debug Then
- lvarInit = TransDebugNullObjectError(lvarInit, cdecl)
- End If
-
- If decl.attrs & FUNC_PTR Then
- Local op:String
- If cdecl.IsStruct() Then op = "." Else op = "->"
- Return lhs.Trans() + op + decl.munged+TransArgs( args,decl, Null)
- Else
- If decl.scope.IsExtern()
- 'Local cdecl:TClassDecl = TClassDecl(decl.scope)
-
- If Not cdecl.IsStruct() Then
- Return Bra(lvarInit) + "->vtbl->" + decl.munged + Bra(TransArgs( args,decl, lvar ))
- End If
- Err "TODO extern types not allowed methods"
- Else
- 'Local cdecl:TClassDecl = TClassDecl(decl.scope)
-
- If cdecl And (cdecl.IsInterface() And Not equalsBuiltInFunc(cdecl, decl)) Then
- Local ifc:String = Bra("(struct " + cdecl.munged + "_methods*)" + Bra("bbObjectInterface((BBObject*)" + obj + lvarInit + ", " + "(BBInterface*)&" + cdecl.munged + "_ifc)"))
- Return ifc + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- Else
- Local class:String = Bra(lvarInit + "->clas" + tSuper)
- Return class + "->" + TransFuncPrefix(decl.scope, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- End If
- End If
- End If
- End If
- Else If TEnumType(lhs.exprType) Then
- If decl.ident = "Ordinal" Then
- Return Bra(TransSubExpr( lhs ))
- Else
- Return decl.munged + Bra(TransSubExpr( lhs ))
- End If
- Else If TInvokeSuperExpr(lhs) Then
-
- Local lvar:String = CreateLocal(lhs, False, False)
- Local lvarInit:String = Bra(lvar + " = " + lhs.Trans())
-
- Local class:String = Bra(lvarInit + "->clas" + tSuper)
- Return class + "->" + TransFuncPrefix(decl.scope, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
- Else
- InternalErr "TCTranslator.TransFunc"
- End If
- 'Return TransSubExpr( lhs )+"->"+decl.munged+TransArgs( args,decl )
- 'Return decl.munged+TransArgs( args,decl, TransSubExpr( lhs ) )
- End If
- ' ((brl_standardio_TCStandardIO_obj*)o->clas)->md_Read(o, xxx, xxx)
- If decl.IsMethod() Or decl.IsField() Then
- If Not (decl.attrs & FUNC_PTR) Then
- Local class:String
-
- If Not scope Then
- scope = decl.scope
- If TClassDecl(scope) And Not TClassDecl(scope).IsStruct() Then
- Local obj:String = Bra(TransObject(scope))
- class = "(" + obj + "o)->clas" + tSuper
- ' Null test
- If opt_debug Then
- Emit TransDebugNullObjectError("o", TClassDecl(scope)) + ";"
- End If
- End If
- Else
- class = Bra("&" + scope.munged) + tSuper
- End If
-
- 'Local obj:String = Bra("struct " + scope.munged + "_obj*")
- 'Local class:String = Bra("(" + obj + "o)->clas" + tSuper)
- 'Local class:String = Bra("&" + decl.scope.munged)
- If TEnumDecl(scope) Then
- ' since we already have the ordinal, we can simply output that
- If decl.ident = "Ordinal" Then
- Return Bra(TransSubExpr( lhs ))
- Else
- Return decl.munged + Bra(TransSubExpr( lhs ))
- End If
- Else If TClassDecl(scope) Then
- If TClassDecl(scope).IsStruct() Then
- Return "_" + decl.munged+TransArgs( args,decl, "o" )
- Else
- Return class + "->" + TransFuncPrefix(scope, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, "o" )
- End If
- End If
-
- InternalErr "TCTranslator.TransFunc.2"
- Else
- ' Null test
- If opt_debug Then
- Emit TransDebugNullObjectError("o", TClassDecl(decl.scope)) + ";"
- End If
-
- Local obj:String
- If TClassDecl(scope) And Not TClassDecl(scope).IsStruct() Then
- obj = Bra(TransObject(decl.scope))
- End If
- Return Bra(obj + "o") + "->" + decl.munged+TransArgs( args,decl )
- End If
- End If
-
- ' for want of a better place to put it...
- ' It may be possible to have the generate via the TransStatic call below, but we'd need to inject a custom arg somewhere else then
- If TEnumDecl(decl.scope) And decl.ident = "Values" Then
- Return "bbEnumValues" + Bra(decl.scope.munged + "_BBEnum_impl")
- End If
-
- Return TransStatic( decl )+TransArgs( args,decl )
- End Method
- Method TransObject:String(decl:TScopeDecl, this:Int = False)
- If decl.ident = "Object"
- Return "BBOBJECT"
- Else If decl.ident = "String" Then
- Return "BBSTRING"
- Else
- If TClassDecl(decl) And TClassDecl(decl).IsStruct() Then
- Local t:String = "struct "
- If decl.IsExtern() Then
- t :+ decl.ident
- Else
- t :+ decl.munged
- End If
-
- If this Then
- Return t + "*"
- Else
- Return t
- End If
- Else
- If decl.IsExtern() Then
- Return "struct " + decl.ident + "*"
- Else
- Return "struct " + decl.munged + "_obj*"
- End If
- End If
- End If
- End Method
- Method TransFuncClass:String(decl:TClassDecl)
- If decl.ident = "Object"
- Return Bra("&bbObjectClass")
- Else
- Return Bra("&" + decl.munged)
- End If
- End Method
- Method TransFuncPrefix:String(decl:TScopeDecl, fdecl:TFuncDecl)
- Local ident:String = fdecl.ident
- If Not decl Or decl.ident = "Object" Or equalsBuiltInFunc(fdecl.ClassScope(), fdecl)
- Return ""
- Else
- If fdecl.IsMethod() Then
- Return "m_"
- Else
- Return "f_"
- End If
- End If
- End Method
- Method TransSuperFunc$( decl:TFuncDecl,args:TExpr[], scope:TScopeDecl )
- Return TransFunc(decl, args, Null, True, scope)
- ' If decl.IsMethod()
- ' Return decl.ClassScope().munged+".md_"+decl.ident+TransArgs( args,decl, "o" )
- ' Else
- ' Return decl.ClassScope().munged+".fn_"+decl.ident+TransArgs( args,decl)
- ' End If
- End Method
- Method TransAscExpr:String(expr:TAscExpr)
- Return "bbStringAsc" + Bra(expr.expr.Trans())
- End Method
- Method TransChrExpr:String(expr:TChrExpr)
- Return "bbStringFromChar" + Bra(expr.expr.Trans())
- End Method
- Method TransLenExpr:String(expr:TLenExpr)
- 'constant strings do not have "->length", so we use the
- 'precalculated value
- If TConstExpr(expr.expr) Then
- If TStringType(expr.expr.exprType) Then
- Return TConstExpr(expr.expr).value.Length
- End If
- End If
-
- If TStringType(expr.expr.exprType) Then
- Return Bra(expr.expr.Trans()) + "->length"
- Else If TArrayType(expr.expr.exprType) Then
- Return Bra(expr.expr.Trans()) + "->scales[0]"
- Else If TCastExpr(expr.expr) Then
- If TArrayType(TCastExpr(expr.expr).expr.exprType) Then
- Return Bra(TCastExpr(expr.expr).expr.Trans()) + "->scales[0]"
- End If
- 'other types just have a length of "1"
- Else
- Return "1"
- End If
- End Method
- Method TransSizeOfExpr:String(expr:TSizeOfExpr)
- Local cexpr:TConstExpr = TConstExpr(expr.expr)
- If cexpr Then
- If TNumericType(cexpr.exprType) Then
- Return "sizeof" + Bra(TransType(cexpr.exprType, ""))
- ' strings
- Else If TStringType(cexpr.exprType) Then
- ' length of const string * 2 bytes per char
- Return Len(cexpr.value) * 2
- End If
- Else
- If TNumericType(expr.expr.exprType) Then
- ' remove Var-ness first, if any
- Local t:TType = expr.expr.exprType.Copy()
- If t._flags & TType.T_VAR Then
- t._flags :~ TType.T_VAR
- End If
- Return "sizeof" + Bra(TransType(t, ""))
- ' strings
- Else If TStringType(expr.expr.exprType) Then
- 'unicode chars each take 2 bytes
- Return Bra(expr.expr.Trans()) + "->length * 2"
- ' arrays
- Else If TArrayType(expr.expr.exprType) Then
- 'normal exprType is something like "int[]" that
- 'is why it has to be checked against elemType
- Local elemType:TType = TArrayType( expr.expr.exprType ).elemType
- ' numerics - including numeric pointers
- If TNumericType(elemType) Then
- 'multiply element count * size of element type
- Return Bra(expr.expr.Trans()) + "->scales[0] * sizeof" + Bra(TransType(elemType, ""))
- ' everything else : string, array, object, function pointer - are all pointers
- Else
- 'arrays of objects are of size: elementCount * pointerSize
- Return Bra(expr.expr.Trans()) + "->scales[0] * sizeof(void*)"
- EndIf
-
- ' objects
- Else If TObjectType(expr.expr.exprType) Then
- If TObjectType( expr.expr.exprType ).classDecl.ident = "Object" Then
- Return "0"
- Else
- Local cdecl:TClassDecl = TObjectType( expr.expr.exprType ).classDecl
-
- If cdecl.IsStruct() Then
- If TIdentTypeExpr(expr.expr) Then
- If cdecl.IsExtern() Then
- Return "sizeof" + Bra("struct " + cdecl.ident)
- Else
- Return "sizeof" + Bra("struct " + cdecl.munged)
- End If
- Else
- Return "sizeof" + Bra(expr.expr.Trans())
- End If
- Else
-
- If TIdentTypeExpr(expr.expr) Then
- Return Bra(Bra(TransFuncClass(cdecl)) + "->obj_size")
- Else
- Return Bra(Bra(expr.expr.Trans()) + "->clas->obj_size")
- End If
-
- End If
- End If
- End If
- End If
- InternalErr "TCTranslator.TransSizeOfExpr"
- End Method
- Method TransStackAllocExpr:String(expr:TStackAllocExpr)
- Return "bbStackAlloc" + Bra(expr.expr.Trans())
- End Method
-
- Method TransFieldOffsetExpr:String(expr:TFieldOffsetExpr)
- Local t:String = "offsetof("
-
- Local cdecl:TClassDecl = TIdentTypeExpr(expr.typeExpr).cdecl
- t :+ "struct " + cdecl.munged
- If Not cdecl.IsStruct() Then
- t :+ "_obj"
- End If
-
- Return t + ", " + TVarExpr(expr.fieldExpr).decl.munged + ")"
- End Method
- '***** Expressions *****
- Method TransConstExpr$( expr:TConstExpr )
- If TStringType(expr.exprType) Then
- Return TransStringConst(expr.value)
- Else
- Return TransValue( expr.exprType,expr.value )
- End If
- End Method
- Method TransStringConst:String(value:String)
- If value Then
- _appInstance.mapStringConsts(value)
- End If
- Local sc:TStringConst = TStringConst(_app.stringConsts.ValueForKey(value))
- Local s:String
- If Not sc Then
- s = "bbEmptyString"
- Else
- sc.used :+ 1
- s = sc.id
- End If
- Return Bra("(BBString*)&" + s)
- End Method
-
- Method StringConstId:String(value:String)
- Local sc:TStringConst = TStringConst(_app.stringConsts.ValueForKey(value))
- If sc Then
- sc.used :+ 1
- Return sc.id
- End If
- InternalErr "Missing const for string : " + value
- End Method
- Method TransNewObjectExpr$( expr:TNewObjectExpr )
- Local t$
- If Not expr.classDecl.IsStruct() And (Not expr.ctor.argDecls Or expr.ctor.argDecls.length = 0) Then
- If expr.instanceExpr Then
- t = "bbObjectNew(" + Bra(expr.instanceExpr.Trans()) + "->clas)"
- Else
- If ClassHasObjectField(expr.classDecl) Then
- t = Bra(TransObject(TScopeDecl(expr.classDecl.actual))) + "bbObjectNew((BBClass *)&" + expr.classDecl.actual.munged + ")"
- Else
- t = Bra(TransObject(TScopeDecl(expr.classDecl.actual))) + "bbObjectAtomicNew((BBClass *)&" + expr.classDecl.actual.munged + ")"
- End If
- End If
- Else
- Local ctorMunged:String
-
- If expr.classDecl = expr.ctor.scope Then
- MungDecl expr.ctor
- ctorMunged = expr.ctor.munged
- Else
- ctorMunged = expr.classDecl.actual.munged + "_" + expr.ctor.ident + MangleMethod(expr.ctor)
- End If
- If expr.instanceExpr Then
- If expr.classDecl.IsStruct() Then
- t = ctorMunged + "_ObjectNew" + TransArgs( expr.args,expr.ctor)
- Else
- t = "_" + ctorMunged + "_ObjectNew" + TransArgs( expr.args,expr.ctor, Bra(expr.instanceExpr.Trans()) + "->clas" )
- End If
- Else
- If ClassHasObjectField(expr.classDecl) And Not expr.classDecl.IsStruct() Then
- t = "_" + ctorMunged + "_ObjectNew" + TransArgs( expr.args,expr.ctor, "&" + expr.classDecl.actual.munged, True )
- Else
- If expr.classDecl.IsStruct() Then
- t = ctorMunged + "_ObjectNew" + TransArgs( expr.args,expr.ctor)
- Else
- t = "_" + ctorMunged + "_ObjectNew" + TransArgs( expr.args,expr.ctor, "&" + expr.classDecl.actual.munged, True)
- End If
- End If
- End If
- End If
- 'Local t$="(new "+expr.classDecl.actual.munged+")"
- 'If expr.ctor t:+"->"+expr.ctor.actual.munged+TransArgs( expr.args,expr.ctor )
- Return t
- End Method
- Method TransNewArrayExpr$( expr:TNewArrayExpr )
- If expr.expr.length = 1 Then
- If TObjectType(expr.ty) And TObjectType(expr.ty).classdecl.IsStruct() And Not IsPointerType(expr.ty) Then
- Return "bbArrayNew1DStruct_" + TObjectType(expr.ty).classdecl.munged + Bra(expr.expr[0].Trans())
- Else
- Return "bbArrayNew1D" + Bra(TransArrayType(expr.ty) + ", " + expr.expr[0].Trans())
- End If
- Else
- ' multiple array
- Local s:String
- For Local i:Int = 0 Until expr.expr.length
- If i Then
- s:+ ", "
- End If
- s:+ expr.expr[i].Trans()
- Next
- If TObjectType(expr.ty) And TObjectType(expr.ty).classdecl.IsStruct() And Not IsPointerType(expr.ty) Then
- Return "bbArrayNewStruct" + Bra(TransArrayType(expr.ty) + ", sizeof" + Bra(TransObject(TObjectType(expr.ty).classdecl)) + ..
- ", _" + TObjectType(expr.ty).classdecl.munged + "_New, " + expr.expr.length + ", " + s)
- Else
- Return "bbArrayNew" + Bra(TransArrayType(expr.ty) + ", " + expr.expr.length + ", " + s)
- End If
- End If
- End Method
- Method TransSelfExpr$( expr:TSelfExpr )
- If (TObjectType(expr.exprType) And TObjectType(expr.exprType).classDecl.IsStruct()) Or ..
- (TClassType(expr.exprType) And TClassType(expr.exprType).classDecl.IsStruct()) Then
- Return "*o"
- End If
-
- Return "o"
- End Method
- Method TransIdentTypeExpr:String(expr:TIdentTypeExpr)
- Return "struct " + expr.cdecl.munged + "_obj"
- End Method
- Method TransCastExpr$( expr:TCastExpr )
- Local t$= expr.expr.Trans()
- Local dst:TType=expr.ty
- Local src:TType=expr.expr.exprType
-
- If TNumericType(src) And (src._flags & TType.T_VAR) Then
- ' var number being cast to a varptr
- If (dst._flags & TType.T_VARPTR) Then
- Return "&" + Bra(t)
- End If
- End If
- If (dst._flags & TType.T_VARPTR) Or (dst._flags & TType.T_VAR) Then
- If Not TConstExpr(expr.expr) Then
- If TInvokeExpr(expr.expr) Return t
- If TByteType( src) Return Bra("&"+t)
- If TShortType( src) Return Bra("&"+t)
- If TFloatType( src) Return Bra("&"+t)
- If TIntType( src) Return Bra("&"+t)
- If TUIntType( src) Return Bra("&"+t)
- If TLongType( src) Return Bra("&"+t)
- If TULongType( src) Return Bra("&"+t)
- If TSizeTType( src) Return Bra("&"+t)
- If TLongIntType( src) Return Bra("&"+t)
- If TULongIntType( src) Return Bra("&"+t)
- If TDoubleType( src) Return Bra("&"+t)
- If TInt128Type( src) Return Bra("&"+t)
- If TFloat128Type( src) Return Bra("&"+t)
- If TDouble128Type( src) Return Bra("&"+t)
- If TFloat64Type( src) Return Bra("&"+t)
- If TWParamType( src) Return Bra("&"+t)
- If TLParamType( src) Return Bra("&"+t)
- If TObjectType(src) Then
- If TObjectType(src).classDecl.IsExtern() Or (dst._flags & TType.T_VARPTR) Then
- Return Bra("&" + t)
- Else
- If TObjectType(dst) Then
- Return Bra("&" + t)
- Else
- Return Bra("bbObjectToFieldOffset" + Bra("(BBObject*)" + "&" + t))
- End If
- End If
- End If
-
- If TFunctionPtrType(src) Return Bra("&"+t)
- 'If TPointerType( src) Return Bra("&"+t)
- Else
- Return Bra(TransValue(TConstExpr(expr.expr).ty, TConstExpr(expr.expr).value))
- End If
- Else If IsPointerType( dst, 0, TType.T_POINTER | TType.T_CHAR_PTR | TType.T_SHORT_PTR )
- If TArrayType(src) Then
- If TArrayType(src).isStatic Then
- Return Bra(t)
- Else
- Return Bra(Bra(TransType(dst, "")) + "BBARRAYDATA(" + t + ",1)")
- End If
- End If
- 'If TByteType(src) And Not IsPointerType(src, TType.T_BYTE, TType.T_POINTER) Return Bra("&"+t)
- If TStringType(src) Then
- Local tmp:String
- If IsPointerType( dst, 0, TType.T_SHORT_PTR ) Or IsPointerType( dst, TType.T_SHORT, TType.T_PTR ) Then
- tmp = CreateLocal2(NewPointerType(TType.T_SHORT), t)
- Else
- tmp = CreateLocal2(NewPointerType(TType.T_BYTE), t)
- End If
- Return tmp
- End If
-
- If (TStringType(dst) And IsPointerType( dst, 0, TType.T_CHAR_PTR | TType.T_SHORT_PTR )) And TNullType(src) Then
- Return "0"
- End If
- If TObjectType(src) Then
- If TObjectType(src).classDecl.IsExtern() Or (src._flags & TType.T_VARPTR) Then
- Return Bra(t)
- Else
- If Not TObjectType(src).classDecl.IsStruct() Then
- Return Bra("bbObjectToFieldOffset" + Bra("(BBObject*)" + t))
- Else
- Return Bra("(BBBYTE*)" + t)
- End If
- End If
- End If
- Local p:String = TransSPointer(dst)
- If TByteType( dst )
- If IsPointerType(src, TType.T_BYTE, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBBYTE" + p + ")"+t)
- Else If TShortType( dst )
- If IsPointerType(src, TType.T_SHORT, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBSHORT" + p + ")"+t)
- Else If TIntType( dst )
- If IsPointerType(src, TType.T_INT, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBINT" + p + ")"+t)
- Else If TUIntType( dst )
- If IsPointerType(src, TType.T_UINT, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBUINT" + p + ")"+t)
- Else If TFloatType( dst )
- If IsPointerType(src, TType.T_FLOAT, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBFLOAT" + p + ")"+t)
- Else If TDoubleType( dst )
- If IsPointerType(src, TType.T_DOUBLE, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBDOUBLE" + p + ")"+t)
- Else If TLongType( dst )
- If IsPointerType(src, TType.T_LONG, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBLONG" + p + ")"+t)
- Else If TULongType( dst )
- If IsPointerType(src, TType.T_ULONG, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBULONG" + p + ")"+t)
- Else If TSizeTType( dst )
- If IsPointerType(src, TType.T_SIZET, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBSIZET" + p + ")"+t)
- Else If TLongIntType( dst )
- If IsPointerType(src, TType.T_LONGINT, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBLONGINT" + p + ")"+t)
- Else If TULongIntType( dst )
- If IsPointerType(src, TType.T_ULONGINT, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBULONGINT" + p + ")"+t)
- Else If TWParamType( dst )
- If IsPointerType(src, TType.T_WPARAM, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(WPARAM" + p + ")"+t)
- Else If TLParamType( dst )
- If IsPointerType(src, TType.T_LPARAM, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(LPARAM" + p + ")"+t)
- Else If TInt128Type( dst )
- If IsPointerType(src, TType.T_INT128, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBINT128" + p + ")"+t)
- Else If TFloat128Type( dst )
- If IsPointerType(src, TType.T_FLOAT128, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBFLOAT128" + p + ")"+t)
- Else If TDouble128Type( dst )
- If IsPointerType(src, TType.T_DOUBLE128, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBDOUBLE128" + p + ")"+t)
- Else If TFloat64Type( dst )
- If IsPointerType(src, TType.T_FLOAT64, TType.T_POINTER & dst._flags) Return t
- If TNumericType( src ) Return Bra("(BBFLOAT64" + p + ")"+t)
-
- 'Else If TIntPtrPtrType( dst )
- ' If TBytePtrType( src) Return Bra("(BBINT**)"+t)
- ' If TShortPtrType( src ) Return Bra("(BBINT**)"+t)
- ' If TIntPtrType( src ) Return Bra("(BBINT**)"+t)
- ' If TFloatPtrType( src ) Return Bra("(BBINT**)"+t)
- ' If TDoublePtrType( src ) Return Bra("(BBINT**)"+t)
- ' If TLongPtrType( src ) Return Bra("(BBINT**)"+t)
- ' If TNumericType( src ) Return Bra("(BBINT**)"+t)
- End If
- Else If TBoolType( dst )
- If TFunctionPtrType(src) Return Bra(Bra( t+"!=0" ) + " && " + Bra( t+"!=&brl_blitz_NullFunctionError" ))
- 'If TFunctionPtrType(src) Return Bra( t+"!=0" )
- If IsPointerType( src, 0, TType.T_POINTER ) Return Bra( t )
- If TBoolType( src ) Return t
- If TByteType( src ) Return Bra( t+"!=0" )
- If TShortType( src ) Return Bra( t+"!=0" )
- If TIntType( src ) Return Bra( t+"!=0" )
- If TUIntType( src ) Return Bra( t+"!=0" )
- If TFloatType( src ) Return Bra( t+"!=0.0f" )
- 'If TCastExpr(expr.expr) And (TArrayType( src ) Or TStringType( src ) Or TObjectType( src )) Then
- ' Return Bra( t+"!= &bbNullObject" )
- 'End If
- If TLongType( src ) Return Bra( t+"!=0" )
- If TULongType( src ) Return Bra( t+"!=0" )
- If TSizeTType( src ) Return Bra( t+"!=0" )
- If TLongIntType( src ) Return Bra( t+"!=0" )
- If TULongIntType( src ) Return Bra( t+"!=0" )
- If TWParamType( src ) Return Bra( t+"!=0" )
- If TLParamType( src ) Return Bra( t+"!=0" )
- If TDoubleType( src ) Return Bra( t+"!=0.0f" )
- If TArrayType( src ) Return Bra( t+"!= &bbEmptyArray" )
- If TStringType( src ) Return Bra( t+"!= &bbEmptyString" )
- If TObjectType( src ) Then
- If TObjectType(src).classDecl.IsExtern() Then
- If Not TObjectType(src).classDecl.IsStruct() Then
- Return Bra( t+"!=0" )
- Else
- Return Bra("1")
- End If
- Else
- If Not TObjectType(src).classDecl.IsStruct() Then
- Return Bra( Bra(Bra("BBObject*") + t )+"!= &bbNullObject" )
- Else
- Return Bra("1")
- End If
- End If
- End If
- If TEnumType( src ) Return Bra( t+"!=0" )
- Else If TIntType( dst )
- If IsPointerType(src,0,TType.T_POINTER) Return Bra("(BBINT)"+t)
- If TBoolType( src ) Return Bra( t )
- If TByteType( src) Return Bra("(BBINT)"+t)
- If TShortType( src) Return Bra("(BBINT)"+t)
- If TBoolType( src ) Return t
- If TIntType( src ) Return t
- If TUIntType( src ) Return Bra("(BBINT)"+t)
- If TFloatType( src ) Return Bra("(BBINT)"+t)
- If TDoubleType( src ) Return Bra("(BBINT)"+t)
- If TLongType( src ) Return Bra("(BBINT)"+t)
- If TULongType( src ) Return Bra("(BBINT)"+t)
- If TSizeTType( src ) Return Bra("(BBINT)"+t)
- If TLongIntType( src ) Return Bra("(BBINT)"+t)
- If TULongIntType( src ) Return Bra("(BBINT)"+t)
- If TWParamType( src ) Return Bra("(BBINT)"+t)
- If TLParamType( src ) Return Bra("(BBINT)"+t)
- If TStringType( src ) Return "bbStringToInt" + Bra(t)
- If TEnumType( src) Return Bra("(BBINT)"+t)
- 'If TIntVarPtrType( src ) Return Bra("*" + t)
- 'If TPointerType( src ) Return Bra("(BBINT)"+t)
- Else If TLongType( dst )
- If IsPointerType(src,0,TType.T_POINTER) Return Bra("(BBLONG)"+t)
- If TBoolType( src ) Return Bra( t )
- If TByteType( src) Return Bra("(BBLONG)"+t)
- If TShortType( src) Return Bra("(BBLONG)"+t)
- If TIntType( src) Return Bra("(BBLONG)"+t)
- If TUIntType( src) Return Bra("(BBLONG)"+t)
- If TLongType( src ) Return t
- If TULongType( src ) Return Bra("(BBLONG)"+t)
- If TSizeTType( src ) Return Bra("(BBLONG)"+t)
- If TLongIntType( src ) Return Bra("(BBLONG)"+t)
- If TULongIntType( src ) Return Bra("(BBLONG)"+t)
- If TWParamType( src ) Return Bra("(BBLONG)"+t)
- If TLParamType( src ) Return Bra("(BBLONG)"+t)
- If TFloatType( src ) Return Bra("(BBLONG)"+t)
- If TDoubleType( src ) Return Bra("(BBLONG)"+t)
- If TStringType( src ) Return "bbStringToLong" + Bra(t)
- If TFloat64Type( src ) Return Bra("(BBLONG)"+t)
- If TEnumType( src) Return Bra("(BBLONG)"+t)
- 'If TPointerType( src ) Return Bra("(BBLONG)"+t)
- Else If TSizeTType( dst )
- If IsPointerType(src,0,TType.T_POINTER) Return Bra("(BBSIZET)"+t)
- If TBoolType( src ) Return Bra( t )
- If TByteType( src) Return Bra("(BBSIZET)"+t)
- If TShortType( src) Return Bra("(BBSIZET)"+t)
- If TIntType( src) Return Bra("(BBSIZET)"+t)
- If TUIntType( src) Return Bra("(BBSIZET)"+t)
- If TLongType( src) Return Bra("(BBSIZET)"+t)
- If TULongType( src) Return Bra("(BBSIZET)"+t)
- If TSizeTType( src ) Return t
- If TLongIntType( src) Return Bra("(BBSIZET)"+t)
- If TULongIntType( src) Return Bra("(BBSIZET)"+t)
- If TWParamType( src ) Return Bra("(BBSIZET)"+t)
- If TLParamType( src ) Return Bra("(BBSIZET)"+t)
- If TFloatType( src ) Return Bra("(BBSIZET)"+t)
- If TDoubleType( src ) Return Bra("(BBSIZET)"+t)
- If TStringType( src ) Return "bbStringToSizet" + Bra(t)
- If TFloat64Type( src ) Return Bra("(BBSIZET)"+t)
- If TEnumType( src) Return Bra("(BBSIZET)"+t)
- 'If TPointerType( src ) Return Bra("(BBLONG)"+t)
- Else If TLongIntType( dst )
- If IsPointerType(src,0,TType.T_POINTER) Return Bra("(BBLONGINT)"+t)
- If TBoolType( src ) Return Bra( t )
- If TByteType( src) Return Bra("(BBLONGINT)"+t)
- If TShortType( src) Return Bra("(BBLONGINT)"+t)
- If TIntType( src) Return Bra("(BBLONGINT)"+t)
- If TUIntType( src) Return Bra("(BBLONGINT)"+t)
- If TLongType( src ) Return Bra("(BBLONGINT)"+t)
- If TULongType( src ) Return Bra("(BBLONGINT)"+t)
- If TSizeTType( src ) Return Bra("(BBLONGINT)"+t)
- If TLongIntType( src ) Return t
- If TULongIntType( src ) Return Bra("(BBLONGINT)"+t)
- If TWParamType( src ) Return Bra("(BBLONGINT)"+t)
- If TLParamType( src ) Return Bra("(BBLONGINT)"+t)
- If TFloatType( src ) Return Bra("(BBLONGINT)"+t)
- If TDoubleType( src ) Return Bra("(BBLONGINT)"+t)
- If TStringType( src ) Return "bbStringToLongInt" + Bra(t)
- If TFloat64Type( src ) Return Bra("(BBLONGINT)"+t)
- If TEnumType( src) Return Bra("(BBLONGINT)"+t)
- 'If TPointerType( src ) Return Bra("(BBLONGINT)"+t)
- Else If TULongIntType( dst )
- If IsPointerType(src,0,TType.T_POINTER) Return Bra("(BBULONGINT)"+t)
- If TBoolType( src ) Return Bra( t )
- If TByteType( src) Return Bra("(BBULONGINT)"+t)
- If TShortType( src) Return Bra("(BBULONGINT)"+t)
- If TIntType( src) Return Bra("(BBULONGINT)"+t)
- If TUIntType( src) Return Bra("(BBULONGINT)"+t)
- If TLongType( src ) Return Bra("(BBULONGINT)"+t)
- If TULongType( src ) Return Bra("(BBULONGINT)"+t)
- If TSizeTType( src ) Return Bra("(BBULONGINT)"+t)
- If TLongIntType( src ) Return Bra("(BBULONGINT)"+t)
- If TULongIntType( src ) Return t
- If TWParamType( src ) Return Bra("(BBULONGINT)"+t)
- If TLParamType( src ) Return Bra("(BBULONGINT)"+t)
- If TFloatType( src ) Return Bra("(BBULONGINT)"+t)
- If TDoubleType( src ) Return Bra("(BBULONGINT)"+t)
- If TStringType( src ) Return "bbStringToULongInt" + Bra(t)
- If TFloat64Type( src ) Return Bra("(BBULONGINT)"+t)
- If TEnumType( src) Return Bra("(BBULONGINT)"+t)
- 'If TPointerType( src ) Return Bra("(BBULONGINT)"+t)
- Else If TFloatType( dst )
- If TBoolType( src ) Return Bra( t )
- If TByteType( src ) Return Bra("(BBFLOAT)"+t)
- If TIntType( src ) Return Bra("(BBFLOAT)"+t)
- If TUIntType( src ) Return Bra("(BBFLOAT)"+t)
- If TShortType( src ) Return Bra("(BBFLOAT)"+t)
- If TFloatType( src ) Return t
- If TDoubleType( src ) Return Bra("(BBFLOAT)"+t)
- If TLongType( src ) Return Bra("(BBFLOAT)"+t)
- If TULongType( src ) Return Bra("(BBFLOAT)"+t)
- If TSizeTType( src ) Return Bra("(BBFLOAT)"+t)
- If TLongIntType( src ) Return Bra("(BBFLOAT)"+t)
- If TULongIntType( src ) Return Bra("(BBFLOAT)"+t)
- If TWParamType( src ) Return Bra("(BBFLOAT)"+t)
- If TLParamType( src ) Return Bra("(BBFLOAT)"+t)
- If TStringType( src ) Return "bbStringToFloat" + Bra(t)
- 'If TFloatVarPtrType( src ) Return Bra("*" + t)
- 'If TPointerType( src ) Return Bra("(BBFLOAT)"+t)
- Else If TDoubleType( dst )
- If TBoolType( src ) Return Bra( t )
- If TByteType( src ) Return Bra("(BBDOUBLE)"+t)
- If TIntType( src ) Return Bra("(BBDOUBLE)"+t)
- If TUIntType( src ) Return Bra("(BBDOUBLE)"+t)
- If TShortType( src ) Return Bra("(BBDOUBLE)"+t)
- If TDoubleType( src ) Return t
- If TFloatType( src ) Return Bra("(BBDOUBLE)"+t)
- If TLongType( src ) Return Bra("(BBDOUBLE)"+t)
- If TULongType( src ) Return Bra("(BBDOUBLE)"+t)
- If TSizeTType( src ) Return Bra("(BBDOUBLE)"+t)
- If TLongIntType( src ) Return Bra("(BBDOUBLE)"+t)
- If TULongIntType( src ) Return Bra("(BBDOUBLE)"+t)
- If TWParamType( src ) Return Bra("(BBDOUBLE)"+t)
- If TLParamType( src ) Return Bra("(BBDOUBLE)"+t)
- If TStringType( src ) Return "bbStringToDouble" + Bra(t)
- 'If TDoubleVarPtrType( src ) Return Bra("*" + t)
- 'If TPointerType( src ) Return Bra("(BBDOUBLE)"+t)
- Else If TStringType( dst )
- If IsPointerType(src, 0, TType.T_POINTER) Return "bbStringFromSizet"+Bra( t )
- If TBoolType( src ) Return "bbStringFromInt"+Bra( t )
- If TByteType( src ) Return "bbStringFromInt"+Bra( t )
- If TShortType( src ) Return "bbStringFromInt"+Bra( t )
- If TIntType( src ) Return "bbStringFromInt"+Bra( t )
- If TUIntType( src ) Return "bbStringFromUInt"+Bra( t )
- If TLongType( src ) Return "bbStringFromLong"+Bra( t )
- If TULongType( src ) Return "bbStringFromULong"+Bra( t )
- If TSizeTType( src ) Return "bbStringFromSizet"+Bra( t )
- If TLongIntType( src ) Return "bbStringFromLongInt"+Bra( t )
- If TULongIntType( src ) Return "bbStringFromULongInt"+Bra( t )
- If TWParamType( src ) Return "bbStringFromWParam"+Bra( t )
- If TLParamType( src ) Return "bbStringFromLParam"+Bra( t )
- If TFloatType( src ) Return "bbStringFromFloat"+Bra( t )
- If TDoubleType( src ) Return "bbStringFromDouble"+Bra( t )
- If TStringType( src ) Then
- If src._flags & TType.T_CHAR_PTR Then
- Return "bbStringFromCString"+Bra( t )
- End If
- If src._flags & TType.T_SHORT_PTR Then
- Return "bbStringFromWString"+Bra( t )
- End If
- If src._flags & TType.T_VAR Then
- If TSliceExpr( expr.expr ) Then
- Return "&" + Bra(t)
- End If
- Return t
- End If
- Return t
- End If
- If TEnumType( src ) Then
- Local ty:TType = TEnumType( src ).decl.ty
- If TByteType( ty ) Return "bbStringFromInt"+Bra( t )
- If TShortType( ty ) Return "bbStringFromInt"+Bra( t )
- If TIntType( ty ) Return "bbStringFromInt"+Bra( t )
- If TUIntType( ty ) Return "bbStringFromUInt"+Bra( t )
- If TLongType( ty ) Return "bbStringFromLong"+Bra( t )
- If TULongType( ty ) Return "bbStringFromULong"+Bra( t )
- If TSizeTType( ty ) Return "bbStringFromSizet"+Bra( t )
- If TLongIntType( ty ) Return "bbStringFromLongInt"+Bra( t )
- If TULongIntType( ty ) Return "bbStringFromULongInt"+Bra( t )
- End If
- 'If TStringVarPtrType( src ) Then
- ' If TSliceExpr( expr.expr ) Then
- ' Return t
- ' End If
- ' Return "*" + t
- 'End If
- 'If TStringCharPtrType( src ) Return "bbStringFromCString"+Bra( t )
- 'Else If TStringVarPtrType( dst )
- 'DebugStop
- Else If TByteType( dst )
- If TBoolType( src ) Return Bra( t )
- If TByteType( src) Return t
- If TShortType( src ) Return Bra("(BBBYTE)"+t)
- If TIntType( src ) Return Bra("(BBBYTE)"+t)
- If TUIntType( src ) Return Bra("(BBBYTE)"+t)
- If TFloatType( src ) Return Bra("(BBBYTE)"+t)
- If TDoubleType( src ) Return Bra("(BBBYTE)"+t)
- If TLongType( src ) Return Bra("(BBBYTE)"+t)
- If TULongType( src ) Return Bra("(BBBYTE)"+t)
- If TSizeTType( src ) Return Bra("(BBBYTE)"+t)
- If TLongIntType( src ) Return Bra("(BBBYTE)"+t)
- If TULongIntType( src ) Return Bra("(BBBYTE)"+t)
- If TWParamType( src ) Return Bra("(BBBYTE)"+t)
- If TLParamType( src ) Return Bra("(BBBYTE)"+t)
- If TStringType( src ) Return Bra("(BBBYTE)bbStringToInt" + Bra(t))
- If TEnumType( src) Return Bra("(BBYTE)"+t)
- 'If TByteVarPtrType( src ) Return Bra("*" + t)
- Else If TShortType( dst )
- If TBoolType( src ) Return Bra( t )
- If TShortType( src) Return t
- If TByteType( src) Return Bra("(BBSHORT)"+t)
- If TIntType( src ) Return Bra("(BBSHORT)"+t)
- If TUIntType( src ) Return Bra("(BBSHORT)"+t)
- If TFloatType( src ) Return Bra("(BBSHORT)"+t)
- If TDoubleType( src ) Return Bra("(BBSHORT)"+t)
- If TLongType( src ) Return Bra("(BBSHORT)"+t)
- If TULongType( src ) Return Bra("(BBSHORT)"+t)
- If TSizeTType( src ) Return Bra("(BBSHORT)"+t)
- If TLongIntType( src ) Return Bra("(BBSHORT)"+t)
- If TULongIntType( src ) Return Bra("(BBSHORT)"+t)
- If TWParamType( src ) Return Bra("(BBSHORT)"+t)
- If TLParamType( src ) Return Bra("(BBSHORT)"+t)
- If TStringType( src ) Return Bra("(BBSHORT)bbStringToInt" + Bra(t))
- If TEnumType( src) Return Bra("(BBSHORT)"+t)
- 'If TShortVarPtrType( src ) Return Bra("*" + t)
- Else If TUIntType( dst )
- If IsPointerType(src,0,TType.T_POINTER) Return Bra("(BBUINT)"+t)
- If TBoolType( src ) Return Bra( t )
- If TShortType( src ) Return Bra("(BBUINT)"+t)
- If TByteType( src) Return Bra("(BBUINT)"+t)
- If TIntType( src ) Return Bra("(BBUINT)"+t)
- If TUIntType( src) Return t
- If TFloatType( src ) Return Bra("(BBUINT)"+t)
- If TDoubleType( src ) Return Bra("(BBUINT)"+t)
- If TLongType( src ) Return Bra("(BBUINT)"+t)
- If TULongType( src ) Return Bra("(BBUINT)"+t)
- If TSizeTType( src ) Return Bra("(BBUINT)"+t)
- If TLongIntType( src ) Return Bra("(BBUINT)"+t)
- If TULongIntType( src ) Return Bra("(BBUINT)"+t)
- If TWParamType( src ) Return Bra("(BBUINT)"+t)
- If TLParamType( src ) Return Bra("(BBUINT)"+t)
- If TStringType( src ) Return "bbStringToUInt" + Bra(t)
- If TEnumType( src) Return Bra("(BBUINT)"+t)
- Else If TULongType( dst )
- If IsPointerType(src,0,TType.T_POINTER) Return Bra("(BBULONG)"+t)
- If TBoolType( src ) Return Bra( t )
- If TShortType( src ) Return Bra("(BBULONG)"+t)
- If TByteType( src) Return Bra("(BBULONG)"+t)
- If TIntType( src ) Return Bra("(BBULONG)"+t)
- If TUIntType( src ) Return Bra("(BBULONG)"+t)
- If TFloatType( src ) Return Bra("(BBULONG)"+t)
- If TDoubleType( src ) Return Bra("(BBULONG)"+t)
- If TLongType( src ) Return Bra("(BBULONG)"+t)
- If TULongType( src) Return t
- If TSizeTType( src ) Return Bra("(BBULONG)"+t)
- If TLongIntType( src ) Return Bra("(BBULONG)"+t)
- If TULongIntType( src ) Return Bra("(BBULONG)"+t)
- If TWParamType( src ) Return Bra("(BBULONG)"+t)
- If TLParamType( src ) Return Bra("(BBULONG)"+t)
- If TStringType( src ) Return "bbStringToULong" + Bra(t)
- If TFloat64Type( src ) Return Bra("(BBULONG)"+t)
- If TEnumType( src) Return Bra("(BBULONG)"+t)
- Else If TFloat64Type( dst )
- If TFloat64Type( src) Return t
- If TLongType( src ) Return Bra("(BBFLOAT64)"+t)
- If TULongType( src ) Return Bra("(BBFLOAT64)"+t)
- If TSizeTType( src ) Return Bra("(BBFLOAT64)"+t)
- Else If TInt128Type( dst )
- If TInt128Type( src) Return t
- If TFloat128Type( src ) Return Bra("(BBINT128)"+t)
- If TDouble128Type( src ) Return Bra("(BBINT128)"+t)
- Else If TFloat128Type( dst )
- If TFloat128Type( src) Return t
- If TInt128Type( src ) Return Bra("(BBFLOAT128)"+t)
- If TDouble128Type( src ) Return Bra("(BBFLOAT128)"+t)
- Else If TDouble128Type( dst )
- If TDouble128Type( src) Return t
- If TInt128Type( src ) Return Bra("(BBDOUBLE128)"+t)
- If TFloat128Type( src ) Return Bra("(BBDOUBLE128)"+t)
- Else If TWParamType( dst )
- If IsPointerType(src,0,TType.T_POINTER) Return Bra("(WPARAM)"+t)
- If TBoolType( src ) Return Bra( t )
- If TByteType( src) Return Bra("(WPARAM)"+t)
- If TShortType( src) Return Bra("(WPARAM)"+t)
- If TIntType( src) Return Bra("(WPARAM)"+t)
- If TUIntType( src) Return Bra("(WPARAM)"+t)
- If TLongType( src) Return Bra("(WPARAM)"+t)
- If TULongType( src) Return Bra("(WPARAM)"+t)
- If TSizeTType( src ) Return Bra("(WPARAM)"+t)
- If TLongIntType( src) Return Bra("(WPARAM)"+t)
- If TULongIntType( src) Return Bra("(WPARAM)"+t)
- If TWParamType( src ) Return t
- If TLParamType( src ) Return Bra("(WPARAM)"+t)
- If TFloatType( src ) Return Bra("(WPARAM)"+t)
- If TDoubleType( src ) Return Bra("(WPARAM)"+t)
- If TStringType( src ) Return "bbStringToWParam" + Bra(t)
- Else If TLParamType( dst )
- If IsPointerType(src,0,TType.T_POINTER) Return Bra("(LPARAM)"+t)
- If TBoolType( src ) Return Bra( t )
- If TByteType( src) Return Bra("(LPARAM)"+t)
- If TShortType( src) Return Bra("(LPARAM)"+t)
- If TIntType( src) Return Bra("(LPARAM)"+t)
- If TUIntType( src) Return Bra("(LPARAM)"+t)
- If TLongType( src) Return Bra("(LPARAM)"+t)
- If TULongType( src) Return Bra("(LPARAM)"+t)
- If TSizeTType( src ) Return Bra("(LPARAM)"+t)
- If TLongIntType( src) Return Bra("(LPARAM)"+t)
- If TULongIntType( src) Return Bra("(LPARAM)"+t)
- If TWParamType( src ) Return Bra("(LPARAM)"+t)
- If TLParamType( src ) Return t
- If TFloatType( src ) Return Bra("(LPARAM)"+t)
- If TDoubleType( src ) Return Bra("(LPARAM)"+t)
- If TStringType( src ) Return "bbStringToLParam" + Bra(t)
- Else If TArrayType( dst )
- If TArrayType( src ) Then
- If TObjectType( TArrayType( dst ).elemType ) And TObjectType( TArrayType( dst ).elemType ).classDecl.ident = "Object" Then
- ' if we are casting to Object[], don't actually cast.
- Return Bra(t)
- Else
- Return "bbArrayCastFromObject" + Bra("(BBOBJECT)" + t + "," + TransArrayType(TArrayType( dst ).elemType))
- End If
- End If
-
- If TObjectType( src) And (TObjectType( src ).classDecl.ident = "___Array" Or TObjectType( src ).classDecl.ident = "Object") Then
- Return "bbArrayCastFromObject" + Bra("(BBOBJECT)" + t + "," + TransArrayType(TArrayType( dst ).elemType))
- End If
- Else If TObjectType( dst )
- 'If TArrayType( src ) Return Bra("(BBOBJECT)"+t)
- 'If TStringType( src ) Return Bra("(BBOBJECT)"+t)
- 'If TObjectType( src ) Return t
- If Not TObjectType( dst ).classDecl.IsExtern() Then
- If TObjectType( dst ).classDecl.IsStruct() Then
- Return TransValue(dst, Null)
- End If
- If TNullType( src ) Return "&bbNullObject"
- If TObjectType(dst).classDecl.IsInterface() Then
- Return Bra(Bra(TransObject(TObjectType(dst).classDecl)) + "bbInterfaceDowncast" + Bra("(BBObject*)" +t + ",(BBInterface*)&" + TObjectType(dst).classDecl.munged + "_ifc"))
- Else
- ' no need to downcast to BBObject, as all objects extend it...
- If TObjectType( dst ).classDecl.ident = "Object" Then
- Return t
- Else
- Return Bra(Bra(TransObject(TObjectType(dst).classDecl)) + "bbObjectDowncast" + Bra("(BBOBJECT)" + t + ",(BBClass*)&" + TObjectType(dst).classDecl.munged))
- End If
- End If
- Else
- If TObjectType( dst ).classDecl.IsInterface() Then
- Return t
- Else
- Return "" ' TODO??
- End If
- End If
- Else If TEnumType( dst )
- If TEnumType( src) Return t
- If TIntegralType(src) Then
- If opt_debug Then
- Return "bbEnumCast_" + TransDebugScopeType(TEnumType(dst).decl.ty) + Bra(TEnumType(dst).decl.munged + "_BBEnum_impl," + t)
- Else
- ' no checking in release mode.
- Return t
- End If
- End If
- End If
- Return TransPtrCast( dst,src,t,"dynamic" )
- Err "C++ translator can't convert "+src.ToString()+" to "+dst.ToString()
- End Method
- Method TransUnaryExpr$( expr:TUnaryExpr )
- Local pri:Int=ExprPri( expr )
- Local t_expr$
- If TVarExpr(expr.expr) Then
- If TObjectType(TVarExpr(expr.expr).exprType) Then
- If TObjectType(TVarExpr(expr.expr).exprType).classDecl.IsStruct() Then
- t_expr = Bra( "1" )
- Else
- t_expr = Bra( expr.expr.Trans() + "!= &bbNullObject")
- End If
- Else If TStringType(TVarExpr(expr.expr).exprType) Then
- t_expr = Bra( expr.expr.Trans() + "!= &bbEmptyString")
- Else If expr.op = "~~" And TEnumType(expr.exprType) Then
- Return Bra("bbEnum" + TEnumType(expr.exprType).decl.munged +"_Mask & ~~" + Bra(TransSubExpr( expr.expr,pri )))
- Else
- t_expr = TransSubExpr( expr.expr,pri )
- End If
- Else
- If expr.op = "~~" And TEnumType(expr.exprType) Then
- Return Bra("bbEnum" + TEnumType(expr.exprType).decl.munged +"_Mask & ~~" + Bra(TransSubExpr( expr.expr,pri )))
- Else
- t_expr = TransSubExpr( expr.expr,pri )
- End If
- End If
- Return TransUnaryOp( expr.op )+t_expr
- End Method
- Method TransBinaryExpr$( expr:TBinaryExpr )
- Local pri:Int=ExprPri( expr )
-
- Local t_lhs$=TransSubExpr( expr.lhs,pri )
- ' If TVarPtrType(expr.lhs.exprType) Then
- ' t_lhs = "*" + t_lhs
- ' End If
- Local t_rhs$=TransSubExpr( expr.rhs,pri-1 )
- ' If TVarPtrType(expr.rhs.exprType) Then
- ' t_rhs = "*" + t_rhs
- ' End If
- If expr.op = "+" Then
- If TStringType(expr.exprType) Then
- Return "bbStringConcat(" + t_lhs + "," + t_rhs + ")"
- Else If TArrayType(expr.exprType) Then
- Return "bbArrayConcat(" + TransArrayType(TArrayType(expr.lhs.exprType).elemType) + "," + t_lhs + "," + t_rhs + ")"
- End If
- End If
-
- If expr.op = "^" Then
- If TIntegralType(expr.exprType) Then
- Return "bbLongPow" + Bra(t_lhs + ", " + t_rhs)
- Else
- Return "bbFloatPow" + Bra(t_lhs + ", " + t_rhs)
- End If
- End If
-
- If expr.op = "mod" Or expr.op = "%" Then
- If TDecimalType(expr.lhs.exprType) Or TDecimalType(expr.rhs.exprType) Then
- Return "bbFloatMod" + Bra(t_lhs + ", " + t_rhs)
- End If
- End If
-
- If (expr.op = "shr" Or expr.op = "&" Or expr.op = "|") Then
- If TIntType(expr.exprType) Then
- t_lhs = "(unsigned int)(" + t_lhs + ")"
- t_rhs = "(unsigned int)(" + t_rhs + ")"
- Else If TLongType(expr.exprType) Then
- t_lhs = "(unsigned long long)(" + t_lhs + ")"
- t_rhs = "(unsigned long long)(" + t_rhs + ")"
- Else If TLongIntType(expr.exprType) Then
- t_lhs = "(unsigned long)(" + t_lhs + ")"
- t_rhs = "(unsigned long)(" + t_rhs + ")"
- End If
- End If
- If TBinaryCompareExpr(expr) Then
- If TStringType(TBinaryCompareExpr(expr).ty) Then
- If t_lhs="&bbNullObject" Then
- err "NULL"
- t_lhs = "&bbEmptyString"
- End If
- If t_rhs="&bbNullObject" Then
- err "NULL"
- t_rhs = "&bbEmptyString"
- End If
- If t_lhs <> "&bbEmptyString" And t_rhs <> "&bbEmptyString" Then
- If expr.op = "=" Or expr.op = "<>" Then
- Return "bbStringEquals" + Bra(t_lhs + ", " + t_rhs) + TransBinaryOp(expr.op, "") + "1"
- Else
- Return "bbStringCompare" + Bra(t_lhs + ", " + t_rhs) + TransBinaryOp(expr.op, "") + "0"
- End If
- End If
- Else If IsPointerType(TBinaryCompareExpr(expr).ty, 0, TType.T_POINTER) Then
- If t_lhs="&bbNullObject" Then
- t_lhs = "0"
- End If
- If t_rhs="&bbNullObject" Then
- t_rhs = "0"
- End If
- Else If TArrayType(TBinaryCompareExpr(expr).ty) Then
- If t_lhs="&bbNullObject" Then
- err "NULL"
- t_lhs = "&bbEmptyArray"
- End If
- If t_rhs="&bbNullObject" Then
- err "NULL"
- t_rhs = "&bbEmptyArray"
- End If
- Else If TObjectType(TBinaryCompareExpr(expr).ty) Then
- Local bcExpr:TBinaryCompareExpr = TBinaryCompareExpr(expr)
- If bcExpr.lhs.exprType.ExtendsType(bcExpr.rhs.exprType) Then
- If t_rhs="&bbNullObject" Then
- t_lhs = Bra("(BBOBJECT)" + t_lhs)
- Else
- t_lhs = Bra(Bra(TransType(bcExpr.rhs.exprType, "*")) + t_lhs)
- End If
- Else If bcExpr.rhs.exprType.ExtendsType(bcExpr.lhs.exprType)
- If t_lhs="&bbNullObject" Then
- t_rhs = Bra("(BBOBJECT)" + t_rhs)
- Else
- t_rhs = Bra(Bra(TransType(bcExpr.lhs.exprType, "*")) + t_rhs)
- End If
- End If
- If t_rhs="&bbNullObject" And TObjectType(bcExpr.lhs.exprType) And TObjectType(bcExpr.lhs.exprType).classDecl.ident = "Object" Then
- If bcExpr.op = "=" Or bcExpr.op = "<>" Then
- Local t:String = t_lhs
- 'If Not TVarExpr(bcExpr.lhs) Then
- ' t = CreateLocal(bcExpr.lhs)
- 'End If
- If bcExpr.op = "="
- Return Bra(t + "==" + t_rhs )
- Else
- Return Bra(t + "!=" + t_rhs )
- End If
- End If
- End If
- If t_lhs="&bbNullObject" And TObjectType(bcExpr.rhs.exprType) And TObjectType(bcExpr.rhs.exprType).classDecl.ident = "Object" Then
- If bcExpr.op = "=" Or bcExpr.op = "<>" Then
- Local t:String = t_rhs
- 'If Not TVarExpr(bcExpr.rhs) Then
- ' t = CreateLocal(bcExpr.rhs)
- 'End If
- If bcExpr.op = "="
- Return Bra(t + "==" + t_lhs )
- Else
- Return Bra(t + "!=" + t_lhs )
- End If
- End If
- End If
- End If
- End If
- Return bra(t_lhs+TransBinaryOp( expr.op,t_rhs )+t_rhs)
- End Method
- Method TransIndexExpr$( expr:TIndexExpr )
- Local t_expr$=TransSubExpr( expr.expr )
- Local t_index$
- If expr.index.length = 1 Then
- If TArraySizeExpr(expr.index[0]) Then
- Local sizes:TArraySizeExpr = TArraySizeExpr(expr.index[0])
- sizes.Trans()
- Local v:String = sizes.val.munged
- Local i:Int = 0
- For i = 0 Until sizes.index.length - 1
- If i Then
- t_index :+ " + "
- End If
- t_index :+ "(*(" + v
- If i Then
- t_index :+ "+" + i
- End If
- t_index :+ ")) * " + sizes.index[i].Trans()
- Next
- t_index :+ " + " + sizes.index[i].Trans()
- ' (*(v+0)) * var1 + (*(v+1)) * var2 + var3
- 'DebugStop
- Else
- t_index=expr.index[0].Trans()
- End If
- End If
- If TStringType( expr.expr.exprType ) Then
- Return Bra(t_expr) + "->buf[" + t_index + "]"
- 'Return "(BBINT)"+t_expr+"["+t_index+"]"
- End If
- If TArrayType( expr.expr.exprType ) Then
- If TFunctionPtrType(TArrayType( expr.expr.exprType ).elemType) Then
- If opt_debug Then
- Return Bra(Bra(TransType(TArrayType( expr.expr.exprType).elemType, "*")) + Bra("BBARRAYDATAINDEX(" + Bra(t_expr) + "," + Bra(t_expr) + "->dims," + t_index + ")")) + "[" + t_index + "]"
- Else
- Return Bra(Bra(TransType(TArrayType( expr.expr.exprType).elemType, "*")) + Bra("BBARRAYDATA(" + t_expr + ",1)")) + "[" + t_index + "]"
- End If
- Else
- If TArrayType( expr.expr.exprType ).isStatic Then
- Return t_expr + "[" + t_index + "]"
- Else
- If opt_debug Then
- Return Bra("(" + TransType(expr.exprType, "") + "*)BBARRAYDATAINDEX(" + Bra(t_expr) + "," + Bra(t_expr) + "->dims," + t_index + ")") + "[" + t_index + "]"
- Else
- Return Bra("(" + TransType(expr.exprType, "") + "*)BBARRAYDATA(" + t_expr + ",1)") + "[" + t_index + "]"
- End If
- End If
- End If
- End If
- 'Local swiz$
- 'If TObjectType( expr.exprType )And expr.exprType.GetClass().IsInterface() swiz=".p"
- 'If ENV_CONFIG="debug" Return t_expr+".At("+t_index+")"+swiz
- Return t_expr+"["+t_index+"]"
- End Method
- Method TransSliceExpr$( expr:TSliceExpr )
- 'DebugStop
- Local t_expr:String=TransSubExpr( expr.expr )
- Local t_args$
- If expr.from Then
- t_args=expr.from.Trans()
- Else
- t_args = "0"
- End If
- If expr.term Then
- t_args:+","+expr.term.Trans()
- Else
- If TArrayType(expr.exprType) Then
- t_args :+ "," + Bra(t_expr) + "->scales[0]"
- 'Else If TStringVarPtrType(expr.exprType) Then
- ' t_args :+ ",(*" + t_expr + ")->length"
- Else
- t_args :+ "," + Bra(t_expr) + "->length"
- End If
- End If
- If TArrayType(expr.exprType) Then
- Local ty:TType = TArrayType(expr.exprType).elemType
- If TObjectType(ty) And TObjectType(ty).classDecl.IsStruct() Then
- Return "bbArraySliceStruct_" + TObjectType(ty).classdecl.munged + Bra( t_expr + "," + t_args )
- Else
- Return "bbArraySlice" + Bra(TransArrayType(ty) + "," + t_expr + "," + t_args)
- End If
- 'Else If TStringVarPtrType(expr.exprType) Then
- ' Return "bbStringSlice" + Bra("*" + t_expr + "," + t_args)
- Else
- Return "bbStringSlice" + Bra(t_expr + "," + t_args)
- End If
- 'Return t_expr+".Slice("+t_args+")"
- End Method
- Method TransArrayExpr$( expr:TArrayExpr )
- Local elemType:TType=TArrayType( expr.exprType ).elemType
- Local tmpData:TLocalDecl =New TLocalDecl.Create( "",TType.voidType,Null )
- MungDecl tmpData
- Local tmpArray:TLocalDecl =New TLocalDecl.Create( "",TType.voidType,Null )
- MungDecl tmpArray
- Local t$
- Local count:Int
- For Local elem:TExpr=EachIn expr.exprs
- If t t:+","
- t:+elem.Trans()
- count :+ 1
- Next
- Local tt$
- ' If Not _env tt="static "
- If Not TFunctionPtrType(elemType) Then
- tt :+ TransType( elemType, tmpData.munged ) + " "+tmpData.munged + "[]"
- Else
- tt :+ TransType( elemType, tmpData.munged + "[]" )
- End If
- Emit tt+"={"+t+"};"
- If TObjectType(elemType) And TObjectType(elemType).classdecl.IsStruct() And Not IsPointerType(elemType) Then
- Emit "BBARRAY " + tmpArray.munged + " = bbArrayFromDataStruct" + Bra(TransArrayType(elemType) + "," + count + "," + tmpData.munged + ", sizeof" + Bra(TransObject(TObjectType(elemType).classdecl))) + ";"
- Else If TEnumType(elemType)
- Emit "BBARRAY " + tmpArray.munged + " = bbArrayFromDataSize" + Bra(TransArrayType(elemType) + "," + count + "," + tmpData.munged + "," + TEnumType(elemType).decl.ty.GetSize() ) + ";"
- Else
- Emit "BBARRAY " + tmpArray.munged + " = bbArrayFromData" + Bra(TransArrayType(elemType) + "," + count + "," + tmpData.munged ) + ";"
- End If
- Return tmpArray.munged
- 'Return "bbArrayFromData" + Bra(TransArrayType(elemType) + "," + count + "," + tmp.munged )
- 'Return "Array<"+TransRefType( elemType, "MM" )+" >("+tmp.munged+","+expr.exprs.Length+")"
- End Method
- Method TransArraySizeExpr$ ( expr:TArraySizeExpr )
- ' scales[0] is the total size of the array
- ' we start from [1] because it is the size of the next full dimension.
- ' in the case of a 2-dimensional array, [1] represents the length of a row.
- Return Bra("(BBARRAY)" + expr.expr.Trans()) + "->scales + 1"
- End Method
- Method TransIntrinsicExpr$( decl:TDecl,expr:TExpr,args:TExpr[] )
- Local texpr$,arg0$,arg1$,arg2$
- If expr texpr=TransSubExpr( expr )
- If args.Length>0 And args[0] arg0=args[0].Trans()
- If args.Length>1 And args[1] arg1=args[1].Trans()
- If args.Length>2 And args[2] arg2=args[2].Trans()
- Local id$=decl.munged[1..]
- Local id2$=id[..1].ToUpper()+id[1..]
- Select id
- '
- 'global functions
- Case "print" Return "Print"+Bra( arg0 )
- Case "error" Return "Error"+Bra( arg0 )
- '
- 'string/array methods
- Case "length" Return texpr+".Length()"
- Case "resize" Return texpr+".Resize"+Bra( arg0 )
- 'string methods
- Case "compare" Return texpr+".Compare"+Bra( arg0 )
- Case "find" Return texpr+".Find"+Bra( arg0+","+arg1 )
- Case "findlast" Return texpr+".FindLast"+Bra( arg0 )
- Case "findlast2" Return texpr+".FindLast"+Bra( arg0+","+arg1 )
- Case "trim" Return texpr+".Trim()"
- Case "join" Return texpr+".Join"+Bra( arg0 )
- Case "split" Return texpr+".Split"+Bra( arg0 )
- Case "replace" Return texpr+".Replace"+Bra( arg0+","+arg1 )
- Case "tolower" Return texpr+".ToLower()"
- Case "toupper" Return texpr+".ToUpper()"
- Case "contains" Return texpr+".Contains"+Bra( arg0 )
- Case "startswith" Return texpr+".StartsWith"+Bra( arg0 )
- Case "endswith" Return texpr+".EndsWith"+Bra( arg0 )
- 'string functions
- Case "fromchar" Return "String"+Bra( "(Char)"+Bra(arg0)+",1" )
- 'math methods
- Case "sin","cos","tan" Return "(float)"+id+Bra( Bra(arg0)+"*D2R" )
- Case "asin","acos","atan" Return "(float)"+Bra( id+Bra(arg0)+"*R2D" )
- Case "atan2" Return "(float)"+Bra( id+Bra(arg0+","+arg1)+"*R2D" )
- Case "sqrt","floor","ceil","log" Return "(float)"+id+Bra( arg0 )
- Case "pow" Return "(float)bbFloatPow"+Bra( arg0+","+arg1 )
- '
- End Select
- InternalErr "TCTranslator.TransIntrinsicExpr"
- End Method
- '***** Statements *****
- Method TransTryStmt$(tryStmt:TTryStmt)
- Emit "{"
-
- If tryStmt.finallyStmt Then MungDecl tryStmt.finallyStmt.finallyLabel
- MungDecl tryStmt.rethrowLabel
- MungDecl tryStmt.endTryLabel
-
- Emit "BBOBJECT ex;"
- If tryStmt.finallyStmt Then
- ' for a nested Try construct, only declare this label once, because leaving such a construct
- ' via Return, Exit Or Continue requires a jump to multiple Finally blocks in direct succession
- ' and the "inner" declarations of retptr wouldn't be visible to the "outer" Finally blocks
- Local alreadyDeclared:Int = False
- For Local t:TTryStmt = EachIn tryStack
- If t.finallyStmt Then alreadyDeclared = True; Exit
- Next
- If Not alreadyDeclared Then
- Emit "void* retptr = &&" + tryStmt.rethrowLabel.munged + ";"
- Else
- Emit "retptr = &&" + tryStmt.rethrowLabel.munged + ";"
- End If
- End If
- Emit "bbExTry {"
-
- ' Try block:
- Emit "case 0: {"
-
- EmitLocalDeclarations tryStmt.block
-
- If opt_debug Then Emit "bbOnDebugPushExState();"
- PushLoopTryStack tryStmt
- tryStack.Push tryStmt
- EmitBlock tryStmt.block
- tryStack.Pop
- PopLoopTryStack
- Emit "bbExLeave();"
- If opt_debug Then Emit "bbOnDebugPopExState();"
-
- ' run the Finally block if control reaches the end of the Try block
- If tryStmt.finallyStmt Then EmitFinallyJmp tryStmt.finallyStmt, tryStmt.endTryLabel
- Emit "}"
- Emit "break;"
-
- ' Catch blocks:
- If tryStmt.catches Then
- Emit "case 1: {"
- If opt_debug Then Emit "bbOnDebugPopExState();"
- If tryStmt.finallyStmt Then
- If opt_debug Then Emit "bbOnDebugPushExState();"
- Emit "ex = bbExCatchAndReenter();"
- Else
- Emit "ex = bbExCatch();"
- End If
- Local s:String = ""
- For Local catchStmt:TCatchStmt = EachIn tryStmt.catches
- MungDecl catchStmt.init
- If TStringType(catchStmt.init.ty) Then
- Emit s + "if (bbObjectStringcast((BBOBJECT)ex) != (BBOBJECT)&bbEmptyString) {"
- Emit TransType(catchStmt.init.ty, catchStmt.init.munged) + " " + catchStmt.init.munged + "=(BBSTRING)ex;"
- Else If TArrayType(catchStmt.init.ty) Then
- Emit s + "if (bbObjectArraycast((BBOBJECT)ex) != &bbEmptyArray) {"
- Emit TransType(catchStmt.init.ty, catchStmt.init.munged) + " " + catchStmt.init.munged + "=(BBARRAY)ex;"
- Else If TObjectType(catchStmt.init.ty) Then
- If TObjectType(catchStmt.init.ty).classDecl.IsInterface() Then
- Emit s + "if (bbInterfaceDowncast((BBObject*)ex,(BBInterface*)&" + TObjectType(catchStmt.init.ty).classDecl.munged + "_ifc) != &bbNullObject) {"
- Else
- Emit s + "if (bbObjectDowncast((BBOBJECT)ex,(BBClass*)&" + TObjectType(catchStmt.init.ty).classDecl.munged + ") != &bbNullObject) {"
- End If
- Emit TransType(catchStmt.init.ty, catchStmt.init.munged) + " " + catchStmt.init.munged + "=" + Bra(TransType(catchStmt.init.ty, catchStmt.init.munged)) + "ex;"
- Else
- Err "Not an object"
- End If
-
- EmitLocalDeclarations catchStmt.block, catchStmt.init
-
- If tryStmt.finallyStmt Then
- PushLoopTryStack tryStmt
- tryStack.Push tryStmt
- EmitBlock catchStmt.block
- tryStack.Pop
- PopLoopTryStack
- Else
- EmitBlock catchStmt.block
- End If
-
- s = "} else "
- Next
-
- If tryStmt.finallyStmt Then
- Emit s + "{"
- ' run the Finally block if an exception was thrown from the Try block but not handled by any of the Catch blocks
- Emit "bbExLeave();"
- If opt_debug Then Emit "bbOnDebugPopExState();"
- EmitFinallyJmp tryStmt.finallyStmt, tryStmt.rethrowLabel
- Emit "}"
-
- ' run the Finally block if an exception was thrown from the Try block and handled by one of the Catch blocks
- Emit "bbExLeave();"
- If opt_debug Then Emit "bbOnDebugPopExState();"
- EmitFinallyJmp tryStmt.finallyStmt, tryStmt.endTryLabel
- Else
- Emit s + "{"
- Emit "goto " + tryStmt.rethrowLabel.munged + ";"
- Emit "}"
- Emit "goto " + tryStmt.endTryLabel.munged + ";"
- End If
-
- Emit "}"
- Emit "break;"
- Else ' no catch blocks exist
- Emit "case 1:"
- 'If opt_debug Then Emit "bbOnDebugPopExState();"
- End If
-
- If tryStmt.finallyStmt Then
- ' run the Finally block if an exception was thrown from a Catch block
- Emit "case 2: {"
- If opt_debug Then Emit "bbOnDebugPopExState();"
- Emit "ex = bbExCatch();"
- Emit "retptr = &&" + tryStmt.rethrowLabel.munged + ";"
- Emit TransLabel(tryStmt.finallyStmt.finallyLabel)
- EmitFinallyStmt tryStmt.finallyStmt
- Emit "goto *retptr;"
- Emit TransLabel(tryStmt.rethrowLabel)
- Emit "bbExThrow(ex);"
- Emit "}"
- Emit "break;"
- Else
- Emit TransLabel(tryStmt.rethrowLabel)
- Emit "bbExThrow(ex);"
- End If
-
- Emit "}"
- Emit "}"
- Emit TransLabel(tryStmt.endTryLabel)
- End Method
-
- Method EmitFinallyJmp(stmt:TFinallyStmt, returnLabel:TLoopLabelDecl)
- Emit "retptr = &&" + returnLabel.munged + ";"
- Emit "goto " + stmt.finallyLabel.munged + ";"
- End Method
-
- Method EmitFinallyStmt(f:TFinallyStmt)
- Emit "{"
- EmitLocalDeclarations f.block
- EmitBlock f.block
- Emit "}"
- End Method
- Method EmitDebugEnterScope(block:TBlockDecl)
- Local scopeIndex:Int
- Local count:Int
- For Local decl:TDecl = EachIn block.Decls()
- If TLocalDecl(decl) Then
- count :+ 1
- End If
- If TGlobalDecl(decl) Then
- count :+ 1
- End If
- Next
-
- ' a method also includes "Self" reference back to parent Type
- If TFuncDecl(block) And TFuncDecl(block).IsMethod() Then
- count :+ 1
- End If
-
- If Not count Then
- Emit "struct BBDebugScope __scope = {"
- Else
- Emit "struct BBDebugScope_" + count + " __scope = {"
- _app.scopeDefs.Insert(String(count), "")
- End If
- If TFuncDecl(block) Then
- Emit "BBDEBUGSCOPE_FUNCTION,"
- If _app.mainFunc = block Then
- ' use the filename as the base function name
- Emit Enquote(StripExt(StripDir(_app.mainModule.filepath))) + ","
- Else
- Emit Enquote(TFuncDecl(block).ident) + ","
- End If
- Else
- Emit "BBDEBUGSCOPE_LOCALBLOCK,"
- Emit "0,"
- End If
-
- Emit "{"
-
- If TFuncDecl(block) And TFuncDecl(block).IsMethod() Then
- Emit "{"
- Emit "BBDEBUGDECL_LOCAL,"
- Emit "~qSelf~q,"
- Emit Enquote(TransDebugScopeType(TClassDecl(block.scope).objectType)) + ","
- Local prefix:String = "&"
- If block.ClassScope().IsStruct() Then
- prefix = ""
- End If
- Emit ".var_address=" + prefix + "o"
- Emit "},"
- scopeIndex:+ 1
- End If
-
- ' block globals
- For Local gdecl:TGlobalDecl = EachIn block.Decls()
- EmitGlobalDebugScope(gdecl, scopeIndex)
- Next
-
- ' iterate through decls and add as appropriate
- For Local decl:TDecl = EachIn block.Decls()
- Local ldecl:TLocalDecl = TLocalDecl(decl)
- If ldecl Then
- Emit "{"
- If ldecl.ty._flags & TType.T_VAR Then
- Emit "BBDEBUGDECL_VARPARAM,"
- Else
- Emit "BBDEBUGDECL_LOCAL,"
- End If
- Emit Enquote(ldecl.ident) + ","
- Emit Enquote(TransDebugScopeType(ldecl.ty)) + ","
- Emit ".var_address=&" + ldecl.munged
- Emit "},"
-
- Continue
- End If
- Next
- Emit "{"
- Emit "BBDEBUGDECL_END"
- Emit "}"
- Emit "}"
-
-
- Emit "};"
-
- ' threaded global
- For Local gdecl:TGlobalDecl = EachIn block.Decls()
- If gdecl.IsThreaded() Then
- Emit "__scope.decls[" + gdecl.scopeIndex + "].var_address = &" + gdecl.munged + ";"
- End If
- Next
-
- Emit "bbOnDebugEnterScope((BBDebugScope *)&__scope);"
- End Method
-
- Method EmitClassThreadedGlobalDebugInit(classDecl:TClassDecl)
- Local classid:String = classDecl.munged
- ' classid + "_scope
- For Local decl:TGlobalDecl = EachIn classDecl.Decls()
- If decl.IsThreaded() Then
- Emit classid + "_scope.decls[" + decl.scopeIndex + "].var_address = &" + decl.munged + ";"
- End If
- Next
- End Method
-
- Method TransDebugNullObjectError:String(variable:String, cdecl:TClassDecl)
- If cdecl.IsStruct() Or cdecl.ident = "String" Or cdecl.ident = "___Array" Then
- 'Return cdecl.munged + "NullObjectTest(" + variable + ")"
- Return variable
- Else
- Return Bra(Bra(TransObject(cdecl)) + "bbNullObjectTest((BBObject*)" + variable + ")")
- End If
- End Method
-
- Method TransAssignStmt$( stmt:TAssignStmt )
- If Not stmt.rhs Return stmt.lhs.Trans()
- Local rhs$=stmt.rhs.Trans()
- Local lhs$=stmt.lhs.TransVar()
- Local s:String
- Local cast:String
-
- If TObjectType(stmt.lhs.exprType) And (Not TObjectType(stmt.lhs.exprType).classdecl.IsStruct() Or IsPointerType(stmt.lhs.exprType)) Then
- If Not IsNumericType(stmt.rhs.exprType) Then
- cast = Bra(TransType(stmt.lhs.exprType, ""))
- End If
- End If
- If IsPointerType(stmt.lhs.exprType, TType.T_BYTE) And rhs = "&bbNullObject" Then
- rhs = "0"
- End If
- If stmt.op = ":%" Then
- If TDecimalType(stmt.lhs.exprType) Or TDecimalType(stmt.rhs.exprType) Then
- Return lhs + "=bbFloatMod" + Bra(lhs + "," + rhs)
- End If
- End If
-
- If TStringType(stmt.lhs.exprType) 'Or TStringVarPtrType(stmt.lhs.exprType) Then
- ' s:+ "{"
- ' s:+ "BBSTRING tmp=" + lhs + ";~n"
- If stmt.op = ":+" Then
- s :+ lhs+"=bbStringConcat("+lhs+","+rhs+")"
- Else If rhs = "&bbNullObject" Then
- s :+ lhs+TransAssignOp( stmt.op )+"&bbEmptyString"
- Else
- s :+ lhs+TransAssignOp( stmt.op )+rhs
- End If
- ' s :+ ";~nBBRETAIN(" + lhs +")~n"
- ' s :+ "BBRELEASE(tmp)~n"
- ' s:+ "}"
- Else If TVarPtrType(stmt.lhs.exprType) Then
- If TCastExpr(stmt.rhs) And IsNumericType(TCastExpr(stmt.rhs).expr.exprType) Then
- rhs = TCastExpr(stmt.rhs).expr.Trans()
- End If
- s :+ lhs+TransAssignOp( stmt.op )+cast+rhs
- Else If TArrayType(stmt.lhs.exprType) Then
- If stmt.op = ":+" Then
- s :+ lhs+"=bbArrayConcat("+ TransArrayType(TArrayType(stmt.lhs.exprType).elemType) + "," + lhs+","+rhs+")"
- Else If rhs = "&bbNullObject" Then
- s :+ lhs+TransAssignOp( stmt.op )+"&bbEmptyArray"
- Else
- s :+ lhs+TransAssignOp( stmt.op )+cast+rhs
- End If
- Else If (TFunctionPtrType(stmt.lhs.exprType) <> Null Or IsPointerType(stmt.lhs.exprType, TType.T_BYTE)) And TInvokeExpr(stmt.rhs) And Not TInvokeExpr(stmt.rhs).invokedWithBraces Then
- If Not cast And TFunctionPtrType(stmt.lhs.exprType) Then
- Local fp:TFunctionPtrType = TFunctionPtrType(stmt.lhs.exprType)
- If fp.func.cdets Then
- cast = fp.func.cdets.TransCast()
- End If
- End If
- rhs = TInvokeExpr(stmt.rhs).decl.munged
- s :+ lhs+TransAssignOp( stmt.op )+cast+rhs
- Else If TObjectType(stmt.lhs.exprType) And TObjectType(stmt.lhs.exprType).classDecl.IsStruct() And rhs = "&bbNullObject" Then
- s :+ lhs+TransAssignOp( stmt.op )+cast+"{}"
- Else
- s :+ lhs+TransAssignOp( stmt.op )+cast+rhs
- End If
- If DEBUG Then
- DebugObject(stmt.lhs.exprType, lhs, Null, True)
- End If
- Return s
- End Method
- Method TransThrowStmt:String( stmt:TThrowStmt )
- Local s:String = "bbExThrow((BBObject *)"
- s:+ stmt.expr.Trans()
- s :+ ")"
- Return s
- End Method
- Method TransAssertStmt$( stmt:TAssertStmt )
- If opt_debug Then
- Emit "if (!" + Bra(stmt.expr.Trans()) + ") {"
- Emit "brl_blitz_RuntimeError(" + stmt.elseExpr.Trans() + ");"
- Emit "}"
- End If
- End Method
- Method TransEndStmt$( stmt:TEndStmt )
- Emit "bbEnd();"
- End Method
- Method TransReleaseStmt$( stmt:TReleaseStmt )
- Emit "bbHandleRelease" + Bra(stmt.expr.Trans()) + ";"
- End Method
- Method TransRestoreDataStmt$( stmt:TRestoreDataStmt )
- Emit "_defDataOffset = &_defData[" + TDataLabelExpr(stmt.label).dataDef.label.index + "];"
- End Method
- Method TransReadDataStmt$( stmt:TReadDataStmt )
- For Local expr:TExpr = EachIn stmt.args
- ' buffer overflow test
- If opt_debug Then
- Emit "if (_defDataOffset - _defData >= " + TDefDataDecl.count + ") brl_blitz_OutOfDataError();"
- End If
- Emit expr.Trans() + " = " + TransDefDataConversion(expr.exprType) + Bra("_defDataOffset++") + ";"
- Next
- End Method
- Method TransNativeStmt$( stmt:TNativeStmt)
- Emit stmt.raw
- End Method
- Method TransFullName:String(decl:TDecl)
- Local s:String
-
- If decl.scope Then
- s:+ TransFullName(decl.scope)
- End If
-
- If s Then
- s :+ " : "
- End If
-
- If TModuleDecl(decl) Then
- s:+ decl.ModuleScope().munged
- Else
- s :+ decl.ident
- End If
-
- If TFuncDecl(decl) Then
- s:+ "()"
- End If
-
- Return s
- End Method
-
- Method ClassHasObjectField:Int(classDecl:TClassDecl, checked:TMap = Null)
- If Not checked Then
- checked = New TMap
- End If
-
- If checked.Contains(classDecl) Then
- Return False
- End If
-
- checked.Insert(classDecl, "")
- If classDecl.superClass Then
- If ClassHasObjectField(classDecl.superClass, checked) Then
- Return True
- End If
- End If
- For Local decl:TFieldDecl = EachIn classDecl.Decls()
- If Not decl.IsSemanted() Then
- decl.Semant()
- End If
- If IsManagedType(decl.ty, checked) Then
- Return True
- End If
- Next
-
- Return False
- End Method
- Method IsManagedType:Int(ty:TType, checked:TMap = Null)
- If IsPointerType(ty) Then
- Return False
- End If
-
- If TStringType(ty) Or (TArrayType(ty) And Not TArrayType(ty).isStatic) Or (TObjectType(ty) And Not TObjectType(ty).classDecl.IsStruct()) Then
- Return True
- End If
- If TArrayType(ty) And TArrayType(ty).isStatic Then
- Return IsManagedType(TArrayType(ty).elemType)
- End If
- If TObjectType(ty) And TObjectType(ty).classDecl.IsStruct() Then
- If ClassHasObjectField(TObjectType(ty).classDecl, checked) Then
- Return True
- End If
- End If
- Return False
- End Method
- '***** Declarations *****
- Rem
- Method EmitFuncProto( decl:TFuncDecl )
- PushMungScope
- decl.Semant
- MungDecl decl
- 'Find decl we override
- Local odecl:TFuncDecl=decl
- While odecl.overrides
- odecl=odecl.overrides
- Wend
- Local args$
- For Local arg:TArgDecl=EachIn odecl.argDecls
- If args args:+","
- args:+TransType( arg.ty )
- Next
- Local t$=TransType( odecl.retType )+" "+decl.munged+Bra( args )
- If decl.IsAbstract() t:+"=0"
- Local q$
- If decl.IsExtern() q:+"extern "
- If decl.IsMethod() q:+"virtual "
- If decl.IsStatic() And decl.ClassScope() q:+"static "
- Emit q+t+";"
- PopMungScope
- End Method
- End Rem
- Method EmitBBClassFuncProto( decl:TFuncDecl)
- 'PushMungScope
- BeginLocalScope
- 'DebugStop
- ' decl.Semant
- ' MungDecl decl
- 'Find decl we override
- Local odecl:TFuncDecl=decl
- 'If odecl.overrides And Not odecl.returnTypeSubclassed Then Return
- 'DebugLog decl.ident
- ' While odecl.overrides
- ' odecl=odecl.overrides
- ' Wend
- MungDecl decl
- Local id$=decl.munged
- Local pre:String
- If decl.IsMethod() Then
- id :+ "_m"
- pre = "m_"
- Else
- id :+ "_f"
- pre = "f_"
- End If
- Local bk:String = ";"
- 'Local pre:String = "typedef "
- 'If odecl.IsExtern() Then
- ' pre = "extern "
- 'End If
- 'DebugLog "id = " + id
- Emit id + " " + pre + FuncDeclMangleIdent(odecl) + ";"
- ' If Not proto Or (proto And Not odecl.IsExtern()) Then
- Rem
- If Not TFunctionPtrType(odecl.retType) Then
- If Not odecl.castTo Then
- Emit pre + TransType( odecl.retType, "" )+" "+ Bra("*" + id)+Bra( args ) + bk
- Else
- If Not odecl.noCastGen Then
- Emit pre + odecl.castTo +" "+Bra("*" + id)+Bra( args ) + bk
- End If
- End If
- Else
- If Not odecl.castTo Then
- Emit pre + TransType( odecl.retType, id )+" "+Bra( args ) + bk
- Else
- If Not odecl.noCastGen Then
- Emit pre + odecl.castTo +" "+Bra( args ) + bk
- End If
- End If
- End If
- For Local t$=EachIn argCasts
- Emit t
- Next
- ' End If
- End Rem
- 'PopMungScope
- EndLocalScope
- End Method
-
- Method FuncDeclMangleIdent:String(fdecl:TFuncDecl)
- If (Not fdecl.ClassScope()) Or (equalsBuiltInFunc(fdecl.classScope(), fdecl)) Then
- Return fdecl.ident
- End If
-
- If Not fdecl.mangled Then
- Local id:String = fdecl.ident
- If fdecl.attrs & FUNC_OPERATOR Then
- id = MungSymbol(id)
- End If
- fdecl.mangled = id + MangleMethod(fdecl)
- End If
- Return fdecl.mangled
- ' If fdecl.olIndex Then
- ' Return fdecl.ident + fdecl.olIndex
- ' Else
- ' Return fdecl.ident
- ' End If
- End Method
- Method EmitClassFuncProto( decl:TFuncDecl, isStruct:Int = False, emitFuncProtos:Int = True)
- 'PushMungScope
- BeginLocalScope
- decl.Semant
- MungDecl decl
- 'Find decl we override
- Local odecl:TFuncDecl=decl
- ' If odecl.overrides Then Return
- While odecl.overrides
- odecl=odecl.overrides
- Wend
- 'Generate 'args' string and arg casts
- Local args$
- ' pass object for method
- If decl.IsMethod() Then
- args :+ TransObject(decl.scope, True)
- End If
- Local argCasts:TStack =New TStack
- For Local i:Int=0 Until decl.argDecls.Length
- Local arg:TArgDecl=decl.argDecls[i]
- Local oarg:TArgDecl=odecl.argDecls[i]
- MungDecl arg
- If args args:+","
- If Not TFunctionPtrType(oarg.ty) Then
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )
- If TArrayType(oarg.ty) And TArrayType(oarg.ty).isStatic Then
- args :+ "[" + TArrayType(oarg.ty).length + "]"
- End If
- Else
- args:+ oarg.castTo + " " + arg.munged
- End If
- Else
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )
- Else
- args:+ oarg.castTo
- End If
- End If
- If arg.ty.EqualsType( oarg.ty ) Continue
- Local t$=arg.munged
- arg.munged=""
- MungDecl arg
- argCasts.Push TransType( arg.ty, arg.munged )+" "+arg.munged+"=static_cast<"+TransType(arg.ty, "")+" >"+Bra(t)+";"
- Next
- Local id$=decl.munged
- Local bk:String = ";"
- Local pre:String = "typedef "
- Local api:String
- If decl.IsMethod() Then
- id :+ "_m"
- Else
- id :+ "_f"
- End If
-
- If decl.attrs & DECL_API_STDCALL Then
- api = " __stdcall "
- End If
- 'If odecl.IsExtern() Then
- ' pre = "extern "
- 'End If
- ' If Not proto Or (proto And Not odecl.IsExtern()) Then
- 'If emitFuncProtos
- If Not TFunctionPtrType(decl.retType) Then
- If Not odecl.castTo Then
- If Not isStruct Then
- Emit pre + TransType( decl.retType, "" )+" "+ Bra(api + "*" + id)+Bra( args ) + bk
- End If
- If emitFuncProtos
- If decl.IsMethod() Then
- Emit TransType(decl.retType, "") + " _" + decl.munged +Bra( args ) + bk
- Else
- Emit TransType(decl.retType, "") + api + " " + decl.munged +Bra( args ) + bk
- End If
- End If
- Else
- If Not odecl.noCastGen Then
- If Not isStruct Then
- If Not decl.overrides Or decl.returnTypeSubclassed Then
- Emit pre + odecl.castTo +" "+Bra(api + "*" + id)+Bra( args ) + bk
- End If
- End If
- If emitFuncProtos
- If decl.IsMethod() Then
- Emit odecl.castTo + " _" + decl.munged +Bra( args ) + bk
- Else
- Emit odecl.castTo + " " + decl.munged +Bra( args ) + bk
- End If
- End If
- End If
- End If
- Else
- If Not odecl.castTo Then
- If Not args Then
- ' for function pointer return type, we need to generate () regardless of whether there are
- ' args or not.
- args = " "
- End If
- ' emit function ptr typedef
- Emit pre + TransType( decl.retType, id + "x") + bk
- ' emit actual typedef (with return type of above typedef)
- Emit pre + TransType( decl.retType, id, args, True ) + bk
- Else
- If Not odecl.noCastGen Then
- Emit pre + odecl.castTo +" "+Bra( args ) + bk
- End If
- End If
- End If
- For Local t$=EachIn argCasts
- Emit t
- Next
- 'End If
- 'PopMungScope
- EndLocalScope
- End Method
- Method EmitFuncDecl( decl:TFuncDecl, proto:Int = False, classFunc:Int = False )
- 'If Not proto And decl.IsAbstract() Return
- Local tmpDebug:Int = opt_debug
- If decl.isNoDebug() Then
- opt_debug = False
- End If
- BeginLocalScope
- decl.Semant
- MungDecl decl
-
- ' export defs?
- If opt_apptype And opt_def And decl.attrs & DECL_EXPORT Then
- If Not _appInstance.exportDefs.Contains(decl) Then
- _appInstance.exportDefs.AddLast(decl)
- End If
- End If
- ' emit nested functions/classes
- If Not proto Then
- ' emit nested classes
- For Local cdecl:TClassDecl = EachIn decl._decls
- MungDecl cdecl
- EmitClassProto(cdecl, False)
- EmitClassDecl(cdecl)
- Next
-
- ' emit nested protos
- For Local fdecl:TFuncDecl = EachIn decl._decls
- EmitFuncDecl(fdecl, True, classFunc)
- Next
-
- ' emit nested bodies
- For Local fdecl:TFuncDecl = EachIn decl._decls
- EmitFuncDecl(fdecl, proto, classFunc)
- Next
- End If
- 'Find decl we override
- Local odecl:TFuncDecl=decl
- While odecl.overrides
- odecl=odecl.overrides
- Wend
- 'Generate 'args' string and arg casts
- Local args$
- ' pass object for method
- If decl.IsMethod() Then
- args :+ TransObject(decl.scope, True) + " o"
- End If
- Local argCasts:TStack =New TStack
- For Local i:Int=0 Until decl.argDecls.Length
- Local arg:TArgDecl=decl.argDecls[i]
- Local oarg:TArgDecl=odecl.argDecls[i]
- MungDecl arg, True
- If args args:+","
- If Not TFunctionPtrType(oarg.ty) Then
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )+" "+arg.munged
- If TArrayType(oarg.ty) And TArrayType(oarg.ty).isStatic Then
- args :+ "[" + TArrayType(oarg.ty).length + "]"
- End If
- Else
- args:+ oarg.castTo + " " + arg.munged
- End If
- Else
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )
- Else
- args:+ oarg.castTo
- End If
- End If
- If arg.ty.EqualsType( oarg.ty ) Continue
- Local t$=arg.munged
- arg.munged=""
- MungDecl arg
- argCasts.Push TransType( arg.ty, arg.munged )+" "+arg.munged+"=static_cast<"+TransType(arg.ty, "")+" >"+Bra(t)+";"
- Next
- Local id$=decl.munged
- If classFunc Then
- If decl.IsMethod() Then
- id = "_" + id
- End If
- Else
- If Not odecl.IsExtern() Then
- id = id
- End If
- End If
- Local iterations:Int = 1
- If decl.attrs & DECL_INLINE Then
- iterations = 2
- End If
- Local origProto:Int = proto
- For Local i:Int = 0 Until iterations
- proto = origProto
- Local bk:String = "{"
- Local pre:String
- Local api:String
- If proto Then
- If odecl.IsExtern() Then
- pre = "extern "
- If TFunctionPtrType(decl.retType) Then
- pre = ""
- End If
- End If
- If decl.attrs & DECL_INLINE And i = 0 Then
- pre = "inline "
- Else
- bk = ";"
- End If
- Else If decl.attrs & DECL_INLINE And i = 0 Then
- pre = "extern "
- bk = ";"
- End If
- If decl.attrs & DECL_INLINE Then
- Select i
- Case 0
- pre = "#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L~n" + pre
- Case 1
- pre = "#else~n" + pre
- End Select
- End If
- If decl.attrs & DECL_API_STDCALL Then
- api = " __stdcall "
- End If
- ' If Not proto Or (proto And Not odecl.IsExtern()) Then
- If Not IsStandardFunc(decl.munged) Then
- If Not TFunctionPtrType(odecl.retType) Then
- If Not odecl.castTo Then
- Emit pre + TransType( decl.retType, "" )+ api + " "+id+Bra( args ) + bk
- Else
- If Not odecl.noCastGen Then
- Emit pre + odecl.castTo + api + " "+id+Bra( args ) + bk
- End If
- End If
- Else
- If Not odecl.castTo Then
- If Not args Then
- ' for function pointer return type, we need to generate () regardless of whether there are
- ' args or not.
- args = " "
- End If
- Emit pre + TransType( decl.retType, id, args )+ bk
- Else
- If Not odecl.noCastGen Then
- Emit pre + odecl.castTo +" "+Bra( args ) + bk
- End If
- End If
- End If
- For Local t$=EachIn argCasts
- Emit t
- Next
- End If
-
- If decl.attrs & DECL_INLINE And i = 0 Then
- proto = Not proto
- End If
- If Not proto Then
- If opt_coverage Then
- EmitCoverageFunction(decl)
- End If
- If PROFILER Then
- Select decl.ident
- Case "WritePixel", "PixelPtr", "CopyPixels", "ConvertPixels", "ConvertPixelsToStdFormat", "ConvertPixelsFromStdFormat"
- Case "OnDebugEnterScope", "OnDebugEnterStm", "GetDbgState", "OnDebugLeaveScope", "OnDebugPopExState", "OnDebugPushExState"
- Default
- DebugPrint("", TransFullName(decl))
- End Select
- End If
-
- If DEBUG Then
- For Local i:Int=0 Until decl.argDecls.Length
- Local arg:TArgDecl=decl.argDecls[i]
- DebugObject(arg.ty, arg.munged, id)
- Next
- End If
- If decl.IsAbstract() Then
- Emit "brl_blitz_NullMethodError();"
- If Not TVoidType( decl.retType ) Then
- Local ret:TReturnStmt = New TReturnStmt.Create(New TConstExpr.Create( decl.retType,"" ).Semant())
- ret.fRetType = decl.retType
- Emit ret.Trans() + ";"
- unreachable = False
- End If
- Else
- decl.Semant()
-
- If opt_debug And decl.IsMethod() And Not TClassDecl(decl.scope).IsStruct() Then
- Emit TransDebugNullObjectError("o", TClassDecl(decl.scope)) + ";"
- End If
- EmitLocalDeclarations(decl)
- EmitBlock decl
- End If
- Emit "}"
- End If
- Next
- If decl.attrs & DECL_INLINE Then
- Emit "#endif"
- End If
- ' reset label ids
- contLabelId = 0
- exitLabelId = 0
- EndLocalScope
- 'PopMungScope
-
- opt_debug = tmpDebug
-
- End Method
-
- Method EmitLocalDeclarations(decl:TScopeDecl, ignoreVar:TValDecl = Null)
- If opt_debug Then
- For Local ldecl:TLocalDecl = EachIn decl.Decls()
- If ldecl <> ignoreVar Then
- If Not TArgDecl(ldecl) And Not ldecl.generated Then
- MungDecl ldecl
- Local ty:TType = ldecl.ty
- Local t:String = TransLocalDeclNoInit(ldecl)
-
- ' If TObjectType( ty ) And TObjectType( ty ).classDecl.IsStruct() Then
- ' t :+ "={}"
- ' End If
-
- Emit t + ";"
- End If
- End If
- Next
- End If
- End Method
- Method EmitClassFieldsProto(classDecl:TClassDecl)
- If classDecl.superClass Then
- EmitClassFieldsProto(classDecl.superClass)
- End If
- For Local decl:TFieldDecl = EachIn classDecl.Decls()
- decl.Semant()
- If Not TFunctionPtrType(decl.ty) Then
- If classDecl.IsExtern() Then
- Emit TransType(decl.ty, "") + " " + decl.ident + ";"
- Else
- Local t:String = TransType(decl.ty, classDecl.actual.munged) + " _" + classDecl.actual.munged.ToLower() + "_" + decl.IdentLower()
-
- If TArrayType(decl.ty) And TArrayType(decl.ty).isStatic Then
- t :+ "[" + TArrayType(decl.ty).length + "]"
- End If
-
- Emit t + ";"
- End If
- Else
- If classDecl.IsExtern() Then
- Emit TransType(decl.ty, decl.ident) + ";"
- Else
- Emit TransType(decl.ty, "_" + classDecl.actual.munged.ToLower() + "_" + decl.IdentLower()) + ";"
- End If
- End If
- Next
- End Method
- Method EmitClassGlobalsProto(classDecl:TClassDecl)
- For Local decl:TGlobalDecl = EachIn classDecl.Decls()
- decl.Semant()
- If TFunctionPtrType(decl.ty) Then
- Emit "extern " + TransThreadedGlobal(decl) + TransRefType( decl.ty, decl.munged ) + ";"
- Else
- Emit "extern " + TransThreadedGlobal(decl) +TransRefType( decl.ty, "" )+" "+ decl.munged+";"
- End If
- Next
- End Method
- Method BBClassClassFuncProtoBuildList( classDecl:TClassDecl, list:TList )
- Local fdecls:TFuncDecl[] = classDecl.GetAllFuncDecls()
- For Local decl:TFuncDecl=EachIn fdecls
- If Not decl.IsSemanted()
- decl.Semant()
- End If
- If Not equalsBuiltInFunc(classDecl, decl) And Not equalsTorFunc(classDecl, decl) Then
- Local fdecl:TFuncDecl = classDecl.GetLatestFuncDecl(decl)
- list.AddLast(fdecl)
- End If
- Next
- End Method
- Method EmitBBClassClassFuncProto( classDecl:TClassDecl )
- Local list:TList = New TList
-
- BBClassClassFuncProtoBuildList(classDecl, list)
- For Local fdecl:TFuncDecl = EachIn list
- EmitBBClassFuncProto( fdecl )
- Next
- End Method
- Method EmitClassProto( classDecl:TClassDecl, emitFuncProtos:Int = True )
-
- If classDecl.args Then
- Return
- End If
- Local classid$=classDecl.munged
- Local superid$
- If classDecl.superClass Then
- superid=classDecl.superClass.actual.munged
- End If
- 'Emit "void _" + classid + "_New" + Bra(TransObject(classdecl) + " o") + ";"
-
- If emitFuncProtos Then
- EmitClassDeclNewListProto(classDecl)
- If classHierarchyHasFunction(classDecl, "Delete") Then
- Emit "void _" + classid + "_Delete" + Bra(TransObject(classdecl) + " o") + ";"
- End If
-
- If classHasFunction(classDecl, "ToString") Then
- Emit "BBSTRING _" + classid + "_ToString" + Bra(TransObject(classdecl) + " o") + ";"
- End If
-
- If classHasFunction(classDecl, "Compare") Then
- Emit "BBINT _" + classid + "_Compare(" + TransObject(classdecl) + " o, BBOBJECT otherObject);"
- End If
-
- If classHasFunction(classDecl, "SendMessage") Then
- Emit "BBOBJECT _" + classid + "_SendMessage(" + TransObject(classdecl) + " o, BBOBJECT message, BBOBJECT source);"
- End If
- End If
- 'Local reserved:String = ",New,Delete,ToString,Compare,SendMessage,_reserved1_,_reserved2_,_reserved3_,".ToLower()
- classDecl.SemantParts()
- 'Local fdecls:TFuncDecl[] = classDecl.GetAllFuncDecls(Null, False)
- For Local decl:TDecl=EachIn classDecl.Decls()
- 'For Local fdecl:TFuncDecl = EachIn fdecls
- Local fdecl:TFuncDecl =TFuncDecl( decl )
- If fdecl
- If Not equalsBuiltInFunc(classDecl, fdecl) And Not equalsTorFunc(classDecl, fdecl) Then
- EmitClassFuncProto( fdecl, , emitFuncProtos )
- Continue
- End If
- EndIf
- Local gdecl:TGlobalDecl =TGlobalDecl( decl )
- If gdecl
- MungDecl gdecl
- ' Emit "static "+TransRefType( gdecl.ty )+" "+gdecl.munged+";"
- Continue
- EndIf
- Next
- Emit ""
- ' emit the class structure
- Emit "struct BBClass_" + classid + " {"
- If classDecl.superClass.ident = "Object" Then
- Emit "BBClass* super;"
- Else
- Emit "struct BBClass_" + classDecl.superClass.munged + "* super;"
- End If
- Emit "void (*free)( BBObject *o );"
- Emit "BBDebugScope* debug_scope;"
- Emit "unsigned int instance_size;"
- Emit "void (*ctor)( BBOBJECT o );"
- Emit "void (*dtor)( BBOBJECT o );"
- If classHierarchyHasFunction(classDecl, "ToString") Then
- Emit "BBSTRING (*ToString)( struct " + classidForFunction(classDecl, "ToString") + "_obj* x );"
- Else
- Emit "BBSTRING (*ToString)( BBOBJECT x );"
- End If
- If classHierarchyHasFunction(classDecl, "Compare") Then
- Emit "BBINT (*Compare)( struct " + classidForFunction(classDecl, "Compare") + "_obj* x, BBOBJECT y );"
- Else
- Emit "int (*Compare)( BBOBJECT x,BBOBJECT y );"
- End If
- If classHierarchyHasFunction(classDecl, "SendMessage") Then
- Emit "BBOBJECT (*SendMessage)( struct " + classidForFunction(classDecl, "SendMessage") + "_obj* x, BBOBJECT m, BBOBJECT s );"
- Else
- Emit "BBOBJECT (*SendMessage)( BBOBJECT o,BBOBJECT m,BBOBJECT s );"
- End If
- Emit "BBINTERFACETABLE itable;"
- Emit "void* extra;"
- Emit "unsigned int obj_size;"
- Emit "unsigned int instance_count;"
- Emit "unsigned int fields_offset;"
- EmitBBClassClassFuncProto(classDecl)
- Emit "};~n"
- If classDecl.IsInterface() Then
- Emit "struct " + classid + "_methods {"
- EmitBBClassClassFuncProto(classDecl)
- Emit "};~n"
- End If
- Emit "struct " + classid + "_obj {"
- Emit "struct BBClass_" + classid + "* clas;"
- BeginLocalScope
- EmitClassFieldsProto(classDecl)
- EndLocalScope
- Emit "};"
- Emit "extern struct BBClass_" + classid + " " + classid + ";"
- EmitClassGlobalsProto(classDecl);
- ' fields
- For Local decl:TFieldDecl = EachIn classDecl.Decls()
- MungDecl decl
- Next
-
- End Method
- Method EmitExternClassFuncProto( classDecl:TClassDecl )
- If classDecl.superClass Then
- EmitExternClassFuncProto(classDecl.superClass)
- End If
- For Local decl:TFuncDecl = EachIn classDecl.Decls()
- decl.Semant()
- ' code is written as a method, but emitted as a function pointer
- ' with self as the first parameter
- Local func:TFuncDecl = TFuncDecl(decl.Copy())
- Local argDecl:TArgDecl = New TArgDecl.Create("This", classDecl.objectType, Null)
- func.argDecls = [argDecl] + func.argDecls
-
- func.Semant()
-
- Local ty:TFunctionPtrType = New TFunctionPtrType
- ty.func = func
-
- Emit TransType(ty, decl.Ident) + ";"
- Next
- End Method
- Method EmitExternClassTypeFuncProto( classDecl:TClassDecl )
- Local doneCtorDtor:Int
- Local iDecl:TClassDecl
- For Local decl:TFuncDecl = EachIn classDecl.GetAllOriginalFuncDecls(Null, True)
- decl.Semant()
-
- ' first interface preceeds ctor/dtor
- If Not doneCtorDtor
- If Not iDecl And TClassDecl(decl.scope).IsInterface() Then
- iDecl = TClassDecl(decl.scope)
- End If
-
- If iDecl
- If iDecl <> TClassDecl(decl.scope) Then
- ' a different interface
- doneCtorDtor = True
- Emit "void(*_ctor)();"
- Emit "void(*_dtor)();"
- End If
- Else
- doneCtorDtor = True
- Emit "void(*_ctor)();"
- Emit "void(*_dtor)();"
- End If
-
- End If
- ' code is written as a method, but emitted as a function pointer
- ' with self as the first parameter
- Local func:TFuncDecl = TFuncDecl(decl.Copy())
- Local argDecl:TArgDecl = New TArgDecl.Create("This", classDecl.objectType, Null)
- func.argDecls = [argDecl] + func.argDecls
-
- func.Semant()
-
- Local ty:TFunctionPtrType = New TFunctionPtrType
- ty.func = func
-
- Emit TransType(ty, decl.Ident) + ";"
- Next
- End Method
-
- Method EmitExternClassProtoTypedef( classDecl:TClassDecl )
- Emit "typedef struct " + classDecl.ident + " " + classDecl.ident + ";"
- End Method
- Method EmitExternClassProto( classDecl:TClassDecl )
-
- ' vtable
- Emit "struct " + classDecl.ident + "Vtbl {"
-
- ' methods
- If classDecl.IsInterface() Then
- EmitExternClassFuncProto(classDecl)
- Else
- EmitExternClassTypeFuncProto(classDecl)
- End If
- Emit "};"
-
- Emit "struct " + classDecl.ident + " {"
- Emit "struct " + classDecl.ident + "Vtbl* vtbl;"
- Emit "};"
- End Method
- Field emittedStructs:TList = New TList
- Method EmitStructClassProto( classDecl:TClassDecl )
- If classDecl.declImported Return
- If emittedStructs.Contains(classDecl) Return
-
- emittedStructs.AddLast(classDecl)
-
- ' emit any dependent structs first
- For Local decl:TFieldDecl = EachIn classDecl.Decls()
- decl.Semant()
-
- If TObjectType(decl.ty) And TObjectType(decl.ty).classDecl.IsStruct() Then
- If Not emittedStructs.Contains(TObjectType(decl.ty).classDecl) Then
- EmitStructClassProto(TObjectType(decl.ty).classDecl)
- End If
- End If
- Next
- If classDecl.IsExtern()
- Emit "struct " + classDecl.ident + " {"
- Else
- EmitClassDeclNewListProto( classDecl )
- For Local fdecl:TFuncDecl=EachIn classDecl.Decls()
-
- If fdecl.IdentLower() <> "new" Then
- EmitClassFuncProto( fdecl, True )
- End If
- Next
-
- Emit "struct " + classDecl.munged + " {"
- End If
- BeginLocalScope
- EmitClassFieldsProto(classDecl)
- EndLocalScope
- Emit "};"
- EmitClassGlobalsProto(classDecl);
- ' struct arrays
- Emit "BBArray *bbArrayNew1DStruct_" + classDecl.munged + "(int length);"
- Emit "BBArray *bbArraySliceStruct_" + classDecl.munged + "(BBArray *inarr, int beg, int end);"
- End Method
- Method classHasFunction:Int(classDecl:TClassDecl, func:String)
- Local f:String = func.ToLower()
- For Local decl:TFuncDecl = EachIn classDecl.Decls()
- If Not decl.IsSemanted() Then
- decl.Semant
- End If
- If decl.IdentLower() = f And equalsBuiltInFunc(classDecl.superClass, decl) Then
- Return True
- End If
- Next
- Return False
- End Method
- Method classHierarchyHasFunction:Int(classDecl:TClassDecl, func:String)
- If classHasFunction(classDecl, func) Return True
- If classDecl.superClass And classDecl.superClass.munged <> "bbObjectClass" Then
- Return classHierarchyHasFunction(classDecl.superClass, func)
- End If
- Return False
- End Method
- Method classidForFunction:String(classDecl:TClassDecl, func:String)
- If classHasFunction(classDecl, func) Return classDecl.munged
- If classDecl.superClass And classDecl.superClass.munged <> "bbObjectClass" Then
- Return classidForFunction(classDecl.superClass, func)
- End If
- Return Null
- End Method
- Method EmitMark( id$,ty:TType,queue:Int )
- If TObjectType( ty )
- If id.EndsWith( ".p" )
- If ty.GetClass().IsInterface() id=id[..-2] Else InternalErr "TCTranslator.EmitMark"
- Else
- If ty.GetClass().IsInterface() InternalErr "TCTranslator.EmitMark"
- EndIf
- If queue
- Emit "gc_mark_q("+id+");"
- Else
- Emit "gc_mark("+id+");"
- EndIf
- Else If TArrayType( ty )
- Emit "gc_mark("+id+");"
- Return
- EndIf
- End Method
-
- Method EmitClassConstsDebugScope(classDecl:TClassDecl, scopeIndex:Int Var)
-
- For Local decl:TConstDecl = EachIn classDecl.Decls()
- EmitConstDebugScope(decl)
- scopeIndex :+ 1
- Next
- End Method
- Method EmitConstDebugScope(decl:TConstDecl)
-
- Emit "{"
- Emit "BBDEBUGDECL_CONST,"
- Emit Enquote(decl.ident) + ","
- Emit Enquote(TransDebugScopeType(decl.ty) + TransDebugMetaData(decl.metadata.metadataString)) + ","
-
- _appInstance.mapStringConsts(decl.value)
-
- Emit ".const_value=(BBString*)&" + StringConstId(decl.value)
- Emit "},"
- End Method
- Method EmitClassFieldsDebugScope(classDecl:TClassDecl, scopeIndex:Int Var)
- ' Don't list superclass fields in our debug scope
- 'If classDecl.superClass Then
- ' EmitClassFieldsDebugScope(classDecl.superClass)
- 'End If
- For Local decl:TFieldDecl = EachIn classDecl.Decls()
- Emit "{"
- Emit "BBDEBUGDECL_FIELD,"
- Emit Enquote(decl.ident) + ","
- Emit Enquote(TransDebugScopeType(decl.ty) + TransDebugMetaData(decl.metadata.metadataString)) + ","
- Local offset:String = ".field_offset=offsetof"
-
- If classDecl.IsStruct() Then
- offset :+ Bra("struct " + classDecl.munged + "," + decl.munged)
- Else
- offset :+ Bra("struct " + classDecl.munged + "_obj," + decl.munged)
- End If
- ' If WORD_SIZE = 8 Then
- ' Emit Bra("BBLONG") + offset
- ' Else
- Emit offset
- ' End If
- 'If Not TFunctionPtrType(decl.ty) Then
- ' Emit TransType(decl.ty, classDecl.actual.munged) + " _" + classDecl.actual.munged.ToLower() + "_" + decl.ident.ToLower() + ";"
- 'Else
- ' Emit TransType(decl.ty, "_" + classDecl.actual.munged.ToLower() + "_" + decl.ident.ToLower()) + ";"
- 'End If
- Emit "},"
-
- scopeIndex :+ 1
- 'offset:+ decl.ty.GetSize()
- Next
-
- 'Return offset
- End Method
-
- Method EmitClassStandardMethodDebugScope(ident:String, ty:String, munged:String)
- Emit "{"
- Emit "BBDEBUGDECL_TYPEMETHOD,"
- Emit Enquote(ident) + ","
- Emit Enquote(ty) + ","
- Emit ".func_ptr=(BBFuncPtr)&" + munged
- Emit "},"
- End Method
-
- Method TransDebugMetaData:String(meta:String)
- If meta Then
- Return "{" + meta + "}"
- End If
- End Method
- Method EmitBBClassFuncsDebugScope(decl:TFuncDecl)
- Emit "{"
- If decl.IsMethod() Then
- Emit "BBDEBUGDECL_TYPEMETHOD,"
- Else
- Emit "BBDEBUGDECL_TYPEFUNCTION,"
- End If
- Emit Enquote(decl.ident) + ","
-
- Local s:String = "("
- For Local i:Int = 0 Until decl.argDecls.length
- If i Then
- s:+ ","
- End If
- s:+ TransDebugScopeType(decl.argDecls[i].ty)
- Next
- s:+ ")"
- If decl.retType Then
- s:+ TransDebugScopeType(decl.retType)
- End If
- s:+ TransDebugMetaData(decl.metadata.metadataString)
- Emit Enquote(s) + ","
- If decl.IsMethod() Or decl.IsCTor() Then
- Emit ".func_ptr=(BBFuncPtr)&_" + decl.munged
- Else
- Emit ".func_ptr=(BBFuncPtr)&" + decl.munged
- End If
- Emit "},"
- End Method
- Method BBClassClassFuncsDebugScopeBuildList(classDecl:TClassDecl, list:TList)
- 'Local reserved:String = ",New,Delete,ToString,Compare,SendMessage,_reserved1_,_reserved2_,_reserved3_,".ToLower()
- For Local decl:TDecl=EachIn classDecl.GetAllFuncDecls(Null, False)
- Local fdecl:TFuncDecl =TFuncDecl( decl )
- If fdecl
- If Not fdecl.IsSemanted()
- fdecl.Semant()
- End If
- If Not classDecl.IsInterface() And fdecl.IsAbstract() Then
- Continue
- End If
- If Not equalsBuiltInFunc(classDecl, fdecl) Then
-
- Local ignore:Int
- Local link:TLink=list._head._succ
- While link<>list._head
- Local ofdecl:TFuncDecl = TFuncDecl(link._value)
- If fdecl.ident = ofdecl.ident And fdecl.EqualsArgs(ofdecl) And fdecl.scope <> ofdecl.scope Then
- If fdecl.overrides Then
- link._value = fdecl
- ignore = True
- Exit
- End If
- EndIf
- link = link._succ
- Wend
- If Not ignore Then
- list.AddLast(fdecl)
- End If
-
- Continue
- End If
- EndIf
- Next
- End Method
-
- Method EmitBBClassClassFuncsDebugScope(classDecl:TClassDecl)
-
- Local list:TList = New TList
-
- BBClassClassFuncsDebugScopeBuildList(classDecl, list)
-
- For Local fdecl:TFuncDecl = EachIn list
- EmitBBClassFuncsDebugScope( fdecl )
- Next
- End Method
- Method EmitClassFuncsDebugScope(classDecl:TClassDecl)
- If classDecl.IsExtern() Return
- Local classid$=classDecl.munged
- Local superid$
- If classDecl.superClass Then
- superid = classDecl.superClass.actual.munged
- End If
- Local ret:String = "()i"
- If opt_issuperstrict Then
- ret = "()"
- End If
-
- If Not classDecl.IsInterface() Then
- EmitClassStandardMethodDebugScope("New", ret, "_" + classid + "_New")
- End If
-
- If classHasFunction(classDecl, "ToString") Then
- EmitClassStandardMethodDebugScope("ToString", "()$", "_" + classidForFunction(classDecl, "ToString") + "_ToString")
- 'Emit "_" + classid + "_ToString,"
- End If
- If classHasFunction(classDecl, "Compare") Then
- EmitClassStandardMethodDebugScope("Compare", "(:Object)i", "_" + classidForFunction(classDecl, "Compare") + "_Compare")
- 'Emit "_" + classid + "_ObjectCompare,"
- End If
- If classHasFunction(classDecl, "SendMessage") Then
- EmitClassStandardMethodDebugScope("SendMessage", "(:Object, :Object):Object", "_" + classidForFunction(classDecl, "SendMessage") + "_SendMessage")
- 'Emit "_" + classid + "_SendMessage,"
- End If
- EmitBBClassClassFuncsDebugScope(classDecl)
- End Method
-
- Method EmitClassGlobalDebugScope( classDecl:TClassDecl, scopeIndex:Int Var )
- For Local decl:TGlobalDecl = EachIn classDecl.Decls()
- EmitGlobalDebugScope(decl, scopeIndex)
- scopeIndex :+ 1
- Next
- End Method
- Method EmitGlobalDebugScope( decl:TGlobalDecl, scopeIndex:Int )
- Emit "{"
- Emit "BBDEBUGDECL_GLOBAL,"
- Emit Enquote(decl.ident) + ","
- Emit Enquote(TransDebugScopeType(decl.ty) + TransDebugMetaData(decl.metadata.metadataString)) + ","
- If decl.IsThreaded() Then
- Emit ".var_address=0"
- decl.scopeIndex = scopeIndex
- Else
- Emit ".var_address=(void*)&" + decl.munged
- End If
- Emit "},"
- End Method
- Method CountBBClassClassFuncsDebugScope(classDecl:TClassDecl, count:Int Var)
- For Local decl:TDecl=EachIn classDecl.GetAllFuncDecls(Null, False)
- Local fdecl:TFuncDecl =TFuncDecl( decl )
- If fdecl
- If Not classDecl.IsInterface() And fdecl.IsAbstract() Then
- Continue
- End If
- If Not equalsBuiltInFunc(classDecl, fdecl) Then
- count :+ 1
- End If
- End If
- Next
- End Method
- Method CountClassConstsDebugScope(classDecl:TClassDecl, count:Int Var)
- For Local decl:TConstDecl = EachIn classDecl.Decls()
- count :+ 1
- Next
- End Method
- Method CountClassFieldsDebugScope(classDecl:TClassDecl, count:Int Var)
- For Local decl:TFieldDecl = EachIn classDecl.Decls()
- count :+ 1
- Next
- End Method
-
- Method DebugScopeDeclCount:Int(classDecl:TClassDecl)
- Local count:Int = 2 ' "New" counts as first one
-
- ' but we don't use "New" for interfaces...
- If classDecl.IsInterface() Or (classDecl.IsExtern() And classDecl.IsStruct()) Then
- count :- 1
- End If
- ' consts
- CountClassConstsDebugScope(classDecl, count)
- ' fields
- CountClassFieldsDebugScope(classDecl, count)
-
- ' standard methods
- If classHasFunction(classDecl, "ToString") Then
- count :+ 1
- End If
- If classHasFunction(classDecl, "Compare") Then
- count :+ 1
- End If
- If classHasFunction(classDecl, "SendMessage") Then
- count :+ 1
- End If
-
- ' methods and functions
- CountBBClassClassFuncsDebugScope(classDecl, count)
-
- ' class globals
- For Local decl:TGlobalDecl = EachIn classDecl.Decls()
- count :+ 1
- Next
-
- Return count
- End Method
- Method EmitClassDecl( classDecl:TClassDecl )
- If classDecl.args Then
- Return
- End If
- PushEnv classDecl
- 'If classDecl.IsTemplateInst()
- ' Return
- 'EndIf
- If classDecl.IsExtern() And Not classDecl.IsStruct() Then
- Return
- EndIf
- Local classid$=classDecl.munged
- Local superid$
- If classDecl.superClass Then
- superid = classDecl.superClass.actual.munged
- End If
- If Not classDecl.IsExtern() Then
- ' process nested classes
- For Local cdecl:TClassDecl = EachIn classDecl._decls
- MungDecl cdecl
- EmitClassProto(cdecl, False)
- EmitClassDecl(cdecl)
- Next
-
- ' process nested functions for new
- Local decl:TFuncDecl
- Try
- decl = classDecl.FindFuncDecl("new",,,,,True,SCOPE_CLASS_HEIRARCHY)
- Catch e:String
- End Try
- If decl And decl.scope = classDecl Then ' only our own New method, not any from superclasses
- decl.Semant
- ' emit nested protos
- For Local fdecl:TFuncDecl = EachIn decl._decls
- EmitFuncDecl(fdecl, True, False)
- Next
-
- ' emit nested bodies
- For Local fdecl:TFuncDecl = EachIn decl._decls
- EmitFuncDecl(fdecl, False, False)
- Next
- End If
-
- EmitClassDeclNewList(classDecl)
-
- If Not (classDecl.attrs & CLASS_STRUCT) Then
- ' process nested functions for delete
- decl = classDecl.FindFuncDecl("delete",,,,,,SCOPE_CLASS_HEIRARCHY)
- If decl Then
- decl.Semant
- ' emit nested protos
- For Local fdecl:TFuncDecl = EachIn decl._decls
- EmitFuncDecl(fdecl, True, False)
- Next
-
- ' emit nested bodies
- For Local fdecl:TFuncDecl = EachIn decl._decls
- EmitFuncDecl(fdecl, False, False)
- Next
- End If
-
- If classHierarchyHasFunction(classDecl, "Delete") Then
- EmitClassDeclDelete(classDecl)
- End If
- End If
-
- Rem
- 'fields ctor
- Emit classid+"::"+classid+"(){"
- For Local decl:TDecl=EachIn classDecl.Semanted()
- Local fdecl:TFieldDecl=TFieldDecl( decl )
- If Not fdecl Continue
- Emit TransField(fdecl,Null)+"="+fdecl.init.Trans()+";"
- Next
- Emit "}"
- End Rem
- Local reserved:String = ",New,Delete,".ToLower()
-
- 'methods
- For Local decl:TDecl=EachIn classDecl.Decls()
-
- Local fdecl:TFuncDecl=TFuncDecl( decl )
- If fdecl
- If reserved.Find("," + fdecl.IdentLower() + ",") = -1 Then
- EmitGDBDebug(fdecl)
- EmitFuncDecl fdecl, , True
- Continue
- End If
- EndIf
-
- 'Local gdecl:TGlobalDecl=TGlobalDecl( decl )
- 'If gdecl
- ' Emit TransRefType( gdecl.ty )+" "+classid+"::"+gdecl.munged+";"
- ' Continue
- ' EndIf
- Next
- Rem
- 'gc_mark
- Emit "void "+classid+"::mark(){"
- If classDecl.superClass
- Emit classDecl.superClass.actual.munged+"::mark();"
- EndIf
- For Local decl:TDecl=EachIn classDecl.Semanted()
- Local fdecl:TFieldDecl=TFieldDecl( decl )
- If fdecl EmitMark TransField(fdecl,Null),fdecl.ty,True
- Next
- Emit "}"
- End Rem
-
- For Local decl:TDecl=EachIn classDecl.Semanted()
- Local gdecl:TGlobalDecl =TGlobalDecl( decl )
- If gdecl
- If TFunctionPtrType(gdecl.ty) Then
- Emit TransThreadedGlobal(gdecl) + TransRefType( gdecl.ty, gdecl.munged ) + ";"
- Else
- Emit TransThreadedGlobal(gdecl) + TransRefType( gdecl.ty, "" )+" "+ gdecl.munged+";"
- End If
- Continue
- EndIf
- Next
-
- reserved = ",New,Delete,ToString,Compare,SendMessage,_reserved1_,_reserved2_,_reserved3_,".ToLower()
- If (classDecl.attrs & CLASS_STRUCT) Then
- Emit "BBARRAYNEW1DSTRUCT_FUNC" + Bra(classid + "," + classid + ", _" + classid + "_New" + ", " + EnQuote("@" + classDecl.ident))
- Emit "BBARRAYSLICESTRUCT_FUNC" + Bra(classid + "," + classid + ", _" + classid + "_New" + ", " + EnQuote("@" + classDecl.ident))
- End If
- End If
-
- 'Emit "struct _" + classid + "_DebugScope{"
- 'Emit "int kind;"
- 'Emit "const char *name;"
- 'Emit "BBDebugDecl decls[" + DebugScopeDeclCount(classDecl) + "];"
- 'Emit "};"
- Local count:Int = DebugScopeDeclCount(classDecl)
-
- ' debugscope
- If count > 1 Then
- _app.scopeDefs.Insert(String(count - 1), "")
- Emit "struct BBDebugScope_" + (count - 1) + " " + classid + "_scope ={"
- Else
- Emit "struct BBDebugScope " + classid + "_scope ={"
- End If
-
- If classDecl.IsInterface() Then
- Emit "BBDEBUGSCOPE_USERINTERFACE,"
- Else If classDecl.IsStruct() Then
- Emit "BBDEBUGSCOPE_USERSTRUCT,"
- Else
- Emit "BBDEBUGSCOPE_USERTYPE,"
- End If
- Emit EnQuote(classDecl.ident + TransDebugMetaData(classDecl.metadata.metadataString)) + ","
- Emit "{"
-
- Local scopeIndex:Int
-
- ' debug const decls
- EmitClassConstsDebugScope(classDecl, scopeIndex)
-
- ' debug field decls
- EmitClassFieldsDebugScope(classDecl, scopeIndex)
-
- ' debug global decls
- EmitClassGlobalDebugScope(classDecl, scopeIndex)
-
- ' debug func decls
- EmitClassFuncsDebugScope(classDecl)
-
- Emit "{"
- Emit "BBDEBUGDECL_END"
- Emit "}"
- Emit "}"
- Emit "};"
- Local fdecls:TFuncDecl[] = classDecl.GetAllFuncDecls()
- Local implementedInterfaces:TMap = classDecl.GetInterfaces()
- Local ifcCount:Int
- If Not classDecl.IsStruct() Then
- ' interface class implementation
- If Not classDecl.IsInterface()
- If Not implementedInterfaces.IsEmpty() Then
- Emit "struct " + classid + "_vdef {"
- For Local ifc:TClassDecl = EachIn implementedInterfaces.Values()
- Emit "struct " + ifc.munged + "_methods interface_" + ifc.ident + ";"
- ifcCount :+ 1
- Next
- Emit "};~n"
-
- Emit "static struct BBInterfaceOffsets " + classid + "_ifc_offsets[] = {"
- For Local ifc:TClassDecl = EachIn implementedInterfaces.Values()
- Emit "{&" + ifc.munged + "_ifc, offsetof(struct " + classid + "_vdef, interface_" + ifc.ident + ")},"
- Next
- Emit "};~n"
-
- Emit "struct " + classid + "_vdef " + classid + "_ifc_vtable = {"
- For Local ifc:TClassDecl = EachIn implementedInterfaces.Values()
- Emit ".interface_" + ifc.ident + "={"
- Local dups:TMap = New TMap
-
- For Local func:TFuncDecl = EachIn ifc.GetImplementedFuncs()
-
- If func.IsMethod() Then
- Local cast:String = Bra( func.munged + "_m" )
-
- For Local f:TFuncDecl = EachIn fdecls
- Mungdecl f
- If f.ident = func.ident And f.EqualsFunc(func) Then
-
- Local id:String = f.ident + "_"
-
- For Local arg:TArgDecl = EachIn f.argDecls
- id :+ TransMangleType(arg.ty)
- Next
-
- If Not dups.ValueForKey(id) Then
- Emit cast + "_" + f.munged + ","
-
- dups.Insert(id, "")
- End If
- Exit
- End If
- Next
-
- End If
- Next
- Emit "},"
- Next
- Emit "};~n"
-
- Emit "struct BBInterfaceTable " + classid + "_itable = {"
- Emit classid + "_ifc_offsets,"
- Emit "&" + classid + "_ifc_vtable,"
- Emit ifcCount
- Emit "};~n"
- End If
- End If
-
- Emit "struct BBClass_" + classid + " " + classid + "={"
-
- ' super class reference
- Emit "&" + classDecl.superClass.munged + ","
- Emit "bbObjectFree,"
- ' debugscope
- Emit "(BBDebugScope*)&" + classid + "_scope,"
- ' object instance size
- Emit "sizeof" + Bra("struct " + classid + "_obj") + ","
-
- ' standard methods
- Emit "(void (*)(BBOBJECT))_" + classid + "_New,"
-
- If Not classHierarchyHasFunction(classDecl, "Delete") Then
- Emit "bbObjectDtor,"
- Else
- Emit "(void (*)(BBOBJECT))_" + classid + "_Delete,"
- End If
-
- If classHierarchyHasFunction(classDecl, "ToString") Then
- Emit "_" + classidForFunction(classDecl, "ToString") + "_ToString,"
- Else
- Emit "bbObjectToString,"
- End If
-
- If classHierarchyHasFunction(classDecl, "Compare") Then
- Emit "_" + classidForFunction(classDecl, "Compare") + "_Compare,"
- Else
- Emit "bbObjectCompare,"
- End If
-
- If classHierarchyHasFunction(classDecl, "SendMessage") Then
- Emit "_" + classidForFunction(classDecl, "SendMessage") + "_SendMessage,"
- Else
- Emit "bbObjectSendMessage,"
- End If
-
- 'Emit "public:"
-
- 'fields
- 'For Local decl:TDecl=EachIn classDecl.Semanted()
- ' Local fdecl:TFieldDecl =TFieldDecl( decl )
- ' If fdecl
- ' Emit TransRefType( fdecl.ty )+" "+fdecl.munged+";"
- ' Continue
- ' EndIf
- 'Next
-
- 'fields ctor
- 'Emit classid+"();"
-
- 'methods
- 'For Local decl:TDecl=EachIn classDecl.Semanted()
- '
- ' Local fdecl:TFuncDecl =TFuncDecl( decl )
- ' If fdecl
- ' EmitFuncProto fdecl
- ' Continue
- ' EndIf
- '
- ' Local gdecl:TGlobalDecl =TGlobalDecl( decl )
- ' If gdecl
- ' Emit "static "+TransRefType( gdecl.ty )+" "+gdecl.munged+";"
- ' Continue
- ' EndIf
- 'Next
-
- 'gc mark
- 'Emit "void mark();"
-
- If classDecl.IsInterface() Or implementedInterfaces.IsEmpty() Then
- ' itable
- Emit "0,"
- ' extra pointer
- Emit "0,"
- Else
- Emit "&" + classid + "_itable,"
- ' extra pointer
- Emit "0,"
- End If
-
- ' obj_size
- Emit TransObjectSize(classDecl)
- ' instance_count
- Emit ",0"
- ' fields_offset
- Emit TransFirstFieldOffset(classDecl)
-
-
- ' methods/funcs
- 'reserved = "New,Delete,ToString,ObjectCompare,SendMessage".ToLower()
- 'For Local decl:TFuncDecl = EachIn classDecl.Decls()
- For Local decl:TFuncDecl = EachIn fdecls
-
- If Not equalsBuiltInFunc(classDecl, decl) And Not equalsTorFunc(classDecl, decl) Then
-
- Local fdecl:TFuncDecl = classDecl.GetLatestFuncDecl(decl)
-
- MungDecl decl
-
- Local t:String = ","
- If fdecl <> decl Then
- MungDecl fdecl
-
- If decl.IsMethod() Then
- t :+ Bra(fdecl.munged + "_m")
- Else
- t :+ Bra(fdecl.munged + "_f")
- End If
- End If
-
- If decl.IsMethod() Then
- t:+ "_"
- End If
-
- t :+ decl.munged
-
- Emit t
- End If
- Next
-
- Emit "};~n"
-
- If classDecl.IsInterface() Then
- Emit "const struct BBInterface " + classid + "_ifc = { (BBClass *)&" + classid + ", (const char *) ~q" + classDecl.ident + "~q };"
- Else
-
- End If
-
- End If
-
- PopEnv
- End Method
- Method EmitEnumDecl(decl:TEnumDecl)
- Local id:String = decl.munged
- Emit "struct BBEnum" + decl.munged + "{"
- Emit "const char * name;"
- Emit "char * type;"
- Emit "char * atype;"
- Emit "int flags;"
- Emit "int length;"
- Emit "void * values;"
- Emit "BBString * names[" + decl.values.length + "];"
- Emit "};"
- If decl.isFlags Then
- Local s:String
- For Local value:TEnumValueDecl = EachIn decl.values
- If s Then
- s :+ "|"
- End If
- s :+ value.Value()
- Next
-
- Emit "const " + TransType(decl.ty, "") + " bbEnum" + decl.munged +"_Mask = " + s + ";"
-
- End If
- Local count:Int
- For Local value:TEnumValueDecl = EachIn decl.values
- count :+ 1
- Next
-
-
- ' debugscope
- If count > 0 Then
- _app.scopeDefs.Insert(String(count), "")
- Emit "struct BBDebugScope_" + count + " " + id + "_scope ={"
- Else
- Emit "struct BBDebugScope " + id + "_scope ={"
- End If
- Emit "BBDEBUGSCOPE_USERENUM,"
- Emit EnQuote(decl.ident) + ","
- Emit "{"
- Local ty:TEnumType = New TEnumType.Create(decl)
- For Local value:TEnumValueDecl = EachIn decl.values
- Emit "{"
- Emit "BBDEBUGDECL_GLOBAL,"
- Emit Enquote(value.ident) + ","
- Emit Enquote(TransDebugScopeType(ty) + TransDebugMetaData(decl.metadata.metadataString)) + ","
- _appInstance.mapStringConsts(value.ident)
- _appInstance.mapStringConsts(value.Value())
- Emit ".const_value=(BBString*)&" + StringConstId(value.Value())
- Emit "},"
- Next
-
- Emit "{"
- Emit "BBDEBUGDECL_END"
- Emit "}"
- Emit "}"
- Emit "};"
-
- Local t:String
- Local n:String
- For Local v:TEnumValueDecl = EachIn decl.values
- If t Then
- t :+ ","
- n :+ ","
- End If
- t :+ v.Value()
- n :+ "(BBString*)&" + StringConstId(v.ident)
- Next
-
- Emit TransType(decl.ty, "") + " " + decl.munged + "_values[" + decl.values.length + "] = {" + t + "};"
-
- Emit "struct BBEnum" + decl.munged + " " + decl.munged + "_BBEnum = {"
- Emit EnQuote(decl.ident) + ","
- Emit TransArrayType(decl.ty) + ","
- Emit TransArrayType(New TEnumType.Create(decl)) + ","
- Emit decl.isFlags + ","
- Emit decl.values.length + ","
- Emit "&" + decl.munged + "_values,"
- Emit "{" + n + "}"
- Emit "};"
-
- Emit "BBEnum * " + decl.munged + "_BBEnum_impl;"
- For Local fdecl:TFuncDecl = EachIn decl.FuncDecls()
- MungDecl fdecl
- Select fdecl.ident
- Case "ToString"
- Emit "BBSTRING " + fdecl.munged + Bra(TransType(decl.ty, "") + " ordinal") + " {"
- Emit "return bbEnumToString_" + TransDebugScopeType(decl.ty) + Bra(decl.munged + "_BBEnum_impl, ordinal") + ";"
- Emit "}"
- Case "TryConvert"
- Emit "BBINT " + fdecl.munged + Bra(TransType(decl.ty, "") + " ordinalValue, " + TransType(decl.ty, "") + " * ordinalResult") + " {"
- Emit "return bbEnumTryConvert_" + TransDebugScopeType(decl.ty) + Bra(decl.munged + "_BBEnum_impl, ordinalValue, ordinalResult") + ";"
- Emit "}"
- End Select
- Next
- End Method
- Method EmitEnumProto(decl:TEnumDecl)
- Emit "extern BBEnum* " + decl.munged + "_BBEnum_impl;"
- For Local fdecl:TFuncDecl = EachIn decl.FuncDecls()
- MungDecl fdecl
- Select fdecl.ident
- Case "ToString"
- Emit "BBSTRING " + fdecl.munged + Bra(TransType(decl.ty, "")) + ";"
- Case "TryConvert"
- Emit "BBINT " + fdecl.munged + Bra(TransType(decl.ty, "") + " ordinalValue, " + TransType(decl.ty, "") + " * ordinalResult") + ";"
- Case "Ordinal"
- ' nothing to generate
- End Select
- Next
-
- Emit "extern const " + TransType(decl.ty, "") + " bbEnum" + decl.munged +"_Mask;"
- End Method
- Method TransObjectSize:String(classDecl:TClassDecl)
- Local t:String
-
- Local firstDecl:TFieldDecl
- Local lastDecl:TFieldDecl
- For Local decl:TFieldDecl = EachIn classDecl.Decls()
- If Not firstDecl Then
- firstDecl = decl
- End If
- lastDecl = decl
- Next
-
- If firstDecl Then
- If firstDecl <> lastDecl Then
- t = "offsetof" + Bra("struct " + classDecl.munged + "_obj," + lastDecl.munged) + " - offsetof" + Bra("struct " + classDecl.munged + "_obj," + firstDecl.munged) + " + sizeof" + Bra(TransType(lastDecl.ty, ""))
- Else
- t = "sizeof" + Bra(TransType(lastDecl.ty, ""))
- End If
- Else
- t = "0"
- End If
- Return t
- End Method
- Method TransFirstFieldOffset:String(classDecl:TClassDecl)
- Local t:String
-
- Local fieldDecl:TFieldDecl
- For Local decl:TFieldDecl = EachIn classDecl.Decls()
- fieldDecl = decl
- Exit
- Next
- If fieldDecl Then
- t = ",offsetof" + Bra("struct " + classDecl.munged + "_obj," + fieldDecl.munged)
- Else
- t = ",sizeof(void*)"
- End If
-
- Return t
- End Method
-
- Method EmitClassDeclNew( classDecl:TClassDecl, fdecl:TFuncDecl )
- Local classid$=classDecl.munged
- Local superid$
- If classDecl.superClass Then
- superid = classDecl.superClass.actual.munged
- End If
- Local t:String = "void _"
-
- If fdecl.argDecls.Length Then
- If classDecl = fdecl.scope Then
- t :+ fdecl.munged
- Else
- t :+ classDecl.munged + "_" + fdecl.ident + MangleMethod(fdecl)
- End If
- Else
- t :+ classid + "_New"
- End If
- 'Find decl we override
- Local odecl:TFuncDecl=fdecl
- If odecl.overrides And odecl.generated Then
- fdecl = odecl.overrides
- Else
- While odecl.overrides
- odecl=odecl.overrides
- Wend
- End If
- Local args:String = TransObject(classdecl, True) + " o"
- For Local i:Int=0 Until fdecl.argDecls.Length
- Local arg:TArgDecl=fdecl.argDecls[i]
- Local oarg:TArgDecl=odecl.argDecls[i]
- MungDecl arg, True
- If args args:+","
- If Not TFunctionPtrType(oarg.ty) Then
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )+" "+arg.munged
- Else
- args:+ oarg.castTo + " " + arg.munged
- End If
- Else
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )
- Else
- args:+ oarg.castTo
- End If
- End If
- If arg.ty.EqualsType( oarg.ty ) Continue
- Next
-
- Emit t + Bra(args) + " {"
-
- Local newDecl:TNewDecl = TNewDecl(fdecl)
-
- If Not classDecl.IsStruct() Then
- ' calling constructor?
- If newDecl And newDecl.chainedCtor Then
- mungdecl newDecl.chainedCtor.ctor
-
- Emit "_" + newDecl.chainedCtor.ctor.ClassScope().munged + "_" + newDecl.chainedCtor.ctor.ident + MangleMethod(newDecl.chainedCtor.ctor) + TransArgs(newDecl.chainedCtor.args, newDecl.chainedCtor.ctor, "o") + ";"
- Else
- If classDecl.superClass.ident = "Object" Then
- Emit "bbObjectCtor((BBOBJECT)o);"
- Else
- If fdecl And fdecl.scope <> classDecl And fdecl.argDecls.Length Then
- t = "o"
- For Local i:Int=0 Until fdecl.argDecls.Length
- Local arg:TArgDecl=fdecl.argDecls[i]
- t :+ ", " + arg.munged
- Next
- Emit "_" + newDecl.ClassScope().munged + "_" + newDecl.ident + MangleMethod(newDecl) + Bra(t) + ";"
- Else
- Emit "_" + superid + "_New((" + TransObject(classDecl.superClass) + ")o);"
- End If
- End If
- End If
-
- Emit "o->clas = &" + classid + ";" ' TODO
- End If
- ' only initialise fields if we are not chaining to a local (in our class) constructor.
- ' this prevents fields being re-initialised through the call-chain.
- If Not newDecl.chainedCtor Or (newDecl.chainedCtor And classDecl <> newDecl.chainedCtor.ctor.scope) Then
- ' field initialisation
- For Local decl:TFieldDecl=EachIn classDecl.Decls()
-
- Local doEmit:Int = True
-
- If Not decl.IsSemanted() Then
- decl.Semant()
- End If
-
- Local fld:String
-
- ' ((int*)((char*)o + 5))[0] =
- fld :+ TransFieldRef(decl, "o")
-
- If decl.init Then
- If TObjectType(decl.ty) And TObjectType(decl.ty).classdecl.IsExtern() And TObjectType(decl.ty).classdecl.IsStruct() Then
- ' skip for uninitialised extern type
- If Not isPointerType(decl.ty) And TConstExpr(decl.init) And Not TConstExpr(decl.init).value Then
- Continue
- End If
- End If
-
- ' initial value
- If (TConstExpr(decl.init) And Not TConstExpr(decl.init).value) And TIntrinsicType(decl.ty) Then
- fld :+ "= "
- If TFloat64Type(decl.ty) Then
- fld :+ "_mm_setzero_si64();"
- Else If TFloat128Type(decl.ty) Then
- fld :+ "_mm_setzero_ps();"
- Else If TDouble128Type(decl.ty) Then
- fld :+ "_mm_setzero_pd();"
- Else If TInt128Type(decl.ty) Then
- fld :+ "_mm_setzero_si128();"
- End If
- Else
- If TObjectType(decl.ty) And TObjectType(decl.ty).classdecl.IsStruct() And Not isPointerType(decl.ty) And (TConstExpr(decl.init) And Not TConstExpr(decl.init).value) Then
- fld = "memset(&" + fld + ", 0, sizeof" + Bra(TransType(decl.ty, "")) + ");"
- Else If TInvokeExpr(decl.init) And Not TInvokeExpr(decl.init).invokedWithBraces Then
- fld :+ "= " + TInvokeExpr(decl.init).decl.munged + ";"
- Else If TObjectType(decl.ty) Then
- fld :+ "= "
- If Not TObjectType(decl.ty).classDecl.IsStruct() Then
- fld :+ Bra(TransObject(TObjectType(decl.ty).classDecl))
- End If
- fld :+ decl.init.Trans() + ";"
- Else If TArrayType(decl.ty) And TArrayType(decl.ty).isStatic Then
- Local idx:String = "i" + fdecl.NextIdx()
- fld = "int " + idx + ";for(" + idx + "=0;" + idx + "<" + TArrayType(decl.ty).length + ";" + idx + "++) " + TransFieldRef(decl, "o") + "[" + idx + "]=" + TransValue(TArrayType(decl.ty).elemType,Null,False) + ";"
- Else
- fld :+ "= " + decl.init.Trans() + ";"
- End If
- End If
- Else
- If TNumericType(decl.ty) Or IsPointerType(decl.ty, 0, TType.T_POINTER) Then
- doEmit = False
- Else If TObjectType(decl.ty) Then
- If TObjectType(decl.ty).classDecl.IsStruct() Then
- fld :+ "= " + TObjectType(decl.ty).classDecl.munged + "_New_ObjectNew();"
- Else
- fld :+ "= &bbNullObject;"
- End If
- Else If TFunctionPtrType(decl.ty) Then
- fld :+ "= &brl_blitz_NullFunctionError;"
- Else If TStringType(decl.ty) Then
- fld :+ "= &bbEmptyString;"
- Else If TArrayType(decl.ty) Then
- If TArrayType(decl.ty).isStatic Then
- Local idx:String = "i" + fdecl.NextIdx()
- fld = "int " + idx + ";for(" + idx + "=0;" + idx + "<" + TArrayType(decl.ty).length + ";" + idx + "++) " + TransFieldRef(decl, "o") + "[" + idx + "]=" + TransValue(TArrayType(decl.ty).elemType,Null,False) + ";"
- Else
- fld :+ "= &bbEmptyArray;"
- End If
- Else If TEnumType(decl.ty) Then
- fld :+ "= " + TEnumType(decl.ty).decl.values[0].Value() + ";"
- End If
- End If
-
- If doEmit Then
- Emit fld
- End If
- Next
-
- End If
- 'Local decl:TFuncDecl = classDecl.FindFuncDecl("new",,,,,,SCOPE_CLASS_LOCAL)
- If fdecl And (fdecl.scope = classDecl) Then ' only our own New method, not any from superclasses
- fdecl.Semant
- If fdecl.munged <> "bbObjectCtor" Then
- EmitLocalDeclarations(fdecl)
- EmitBlock fdecl
- End If
- End If
- '
- Emit "}"
- End Method
- Method EmitClassDeclNewList( classDecl:TClassDecl )
- Local classid$=classDecl.munged
- Local newDecls:TFuncDeclList = TFuncDeclList(classdecl.FindDeclList("new", True,,,True))
-
- For Local fdecl:TFuncDecl = EachIn newDecls
-
- MungDecl fdecl
-
- If fdecl.scope <> classDecl Then
- fdecl.Clear()
- EmitClassDeclNew(classDecl, fdecl)
- Else
- EmitClassDeclNew(classDecl, fdecl)
- End If
- ' generate "objectNew" function if required
- If (fdecl.argDecls And fdecl.argDecls.length) Or classDecl.IsStruct() Then
- EmitClassDeclNewInit(classDecl, fdecl)
- End If
-
- Next
- End Method
- Method EmitClassDeclNewListProto( classDecl:TClassDecl )
- Local classid$=classDecl.munged
- 'Local superid$=classDecl.superClass.actual.munged
- Local newDecls:TFuncDeclList = TFuncDeclList(classdecl.FindDeclList("new", True,,,True))
-
- For Local fdecl:TFuncDecl = EachIn newDecls
-
- EmitClassDeclNewProto(classDecl, fdecl)
-
- ' generate "objectNew" function if required
- If (fdecl.argDecls And fdecl.argDecls.length) Or classDecl.IsStruct() Then
- EmitClassDeclObjectNewProto(classDecl, fdecl)
- End If
-
- Next
- End Method
-
- Method EmitClassDeclNewInit(classDecl:TClassDecl, fdecl:TFuncDecl)
- Local funcMunged:String
-
- If classDecl = fdecl.scope Then
- funcMunged = fdecl.munged
- Else
- funcMunged = classDecl.munged + "_" + fdecl.ident + MangleMethod(fdecl)
- End If
- Local t:String = TransObject(classdecl) + " "
-
- If Not classDecl.IsStruct() Then
- t :+ "_"
- End If
- t :+ funcMunged + "_ObjectNew"
- 'Find decl we override
- Local odecl:TFuncDecl=fdecl
- While odecl.overrides
- odecl=odecl.overrides
- Wend
- Local args:String
-
- If Not classDecl.IsStruct() Then
- args = "BBClass * clas"
- End If
- For Local i:Int=0 Until fdecl.argDecls.Length
- Local arg:TArgDecl=fdecl.argDecls[i]
- Local oarg:TArgDecl=odecl.argDecls[i]
- MungDecl arg, True
- If args args:+","
- If Not TFunctionPtrType(oarg.ty) Then
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )+" "+arg.munged
- Else
- args:+ oarg.castTo + " " + arg.munged
- End If
- Else
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )
- Else
- args:+ oarg.castTo
- End If
- End If
- If arg.ty.EqualsType( oarg.ty ) Continue
- Next
-
- Emit t + Bra(args) + " {"
- t = TransObject(classdecl) + " o"
- If classDecl.IsStruct() Then
- t :+ " = {"
- Local fields:Int
- For Local f:TFieldDecl = EachIn classDecl.Decls()
- If fields Then
- t :+ ","
- End If
- fields = True
- t :+ TransValue(f.ty, "", True)
- Next
- Emit t + "};"
- Else
- t :+ " = " + Bra(TransObject(classdecl))
- If ClassHasObjectField(classDecl) Then
- t :+ "bbObjectNewNC"
- Else
- t :+ "bbObjectAtomicNewNC"
- End If
-
- Emit t + "(clas);"
- End If
-
- t = "_" + funcMunged
-
- If classDecl.IsStruct() Then
- t :+ "(&o"
- Else
- t :+ "(o"
- End If
-
- For Local i:Int=0 Until fdecl.argDecls.Length
- Local arg:TArgDecl=fdecl.argDecls[i]
- t :+ ", " + arg.munged
- Next
-
- Emit t + ");"
-
- Emit "return o;"
-
- Emit "}"
-
- End Method
- Method EmitClassDeclNewProto( classDecl:TClassDecl, fdecl:TFuncDecl )
- Local classid$=classDecl.munged
- Local superid$
- If classDecl.superClass Then
- superid = classDecl.superClass.actual.munged
- End If
- Local t:String = "void _"
-
- If fdecl.argDecls.Length Then
- If classDecl = fdecl.scope Then
- If Not fdecl.munged Then
- MungDecl fdecl
- End If
- t :+ fdecl.munged
- Else
- t :+ classDecl.munged + "_" + fdecl.ident + MangleMethod(fdecl)
- End If
- Else
- t :+ classid + "_New"
- End If
-
- 'Find decl we override
- Local odecl:TFuncDecl=fdecl
- While odecl.overrides
- odecl=odecl.overrides
- Wend
- Local args:String = TransObject(classdecl, True) + " o"
- For Local i:Int=0 Until fdecl.argDecls.Length
- Local arg:TArgDecl=fdecl.argDecls[i]
- Local oarg:TArgDecl=odecl.argDecls[i]
- MungDecl arg, True
- If args args:+","
- If Not TFunctionPtrType(oarg.ty) Then
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )+" "+arg.munged
- Else
- args:+ oarg.castTo + " " + arg.munged
- End If
- Else
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )
- Else
- args:+ oarg.castTo
- End If
- End If
- If arg.ty.EqualsType( oarg.ty ) Continue
- Next
-
- Emit t + Bra(args) + ";"
- End Method
-
- Method EmitClassDeclObjectNewProto(classDecl:TClassDecl, fdecl:TFuncDecl)
- Local t:String = TransObject(classdecl) + " "
-
- If Not classDecl.IsStruct() Then
- t :+ "_"
- End If
-
- If classDecl = fdecl.scope Then
- t :+ fdecl.munged
- Else
- t :+ classDecl.munged + "_" + fdecl.ident + MangleMethod(fdecl)
- End If
-
- t:+ "_ObjectNew"
-
- 'Find decl we override
- Local odecl:TFuncDecl=fdecl
- While odecl.overrides
- odecl=odecl.overrides
- Wend
- Local args:String
- If Not classDecl.IsStruct() Then
- args = "BBClass * clas"
- End If
- For Local i:Int=0 Until fdecl.argDecls.Length
- Local arg:TArgDecl=fdecl.argDecls[i]
- Local oarg:TArgDecl=odecl.argDecls[i]
- MungDecl arg, True
- If args args:+","
- If Not TFunctionPtrType(oarg.ty) Then
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )+" "+arg.munged
- Else
- args:+ oarg.castTo + " " + arg.munged
- End If
- Else
- If Not odecl.castTo Then
- args:+TransType( oarg.ty, arg.munged )
- Else
- args:+ oarg.castTo
- End If
- End If
- If arg.ty.EqualsType( oarg.ty ) Continue
- Next
-
- Emit t + Bra(args) + ";"
- End Method
- Method EmitClassDeclDelete( classDecl:TClassDecl )
- Local classid$=classDecl.munged
- Local superid$=classDecl.superClass.actual.munged
- ' New
- ' If opt_issuperstrict Then
- Emit "void _" + classid + "_Delete" + Bra(TransObject(classdecl) + " o") + " {"
- ' Else
- ' Emit "int _" + classid + "_Delete" + Bra(TransObject(classdecl) + " o") + " {"
- ' End If
- Local decl:TFuncDecl = classDecl.FindFuncDecl("delete",,,,,,SCOPE_CLASS_HEIRARCHY)
- If decl And decl.ClassScope() = classDecl Then
- decl.Semant
- EmitLocalDeclarations(decl)
- EmitBlock decl
- End If
- ' field cleanup
- For Local decl:TFieldDecl=EachIn classDecl.Decls()
- ' String
- If TStringType(decl.declTy) Then
- Emit "BBRELEASE(" + TransFieldRef(decl, "o") + ")"
- End If
- ' object
- ' TODO
- Next
- ' finally, call super delete
- EmitClassDeclDeleteDtor(classDecl)
- '
- Emit "}"
- End Method
-
- Method EmitClassDeclDeleteDtor( classDecl:TClassDecl )
- Local superid$=classDecl.superClass.actual.munged
-
- If classDecl.superClass.ident = "Object" Or Not classHierarchyHasFunction(classDecl.superClass, "Delete") Then
- Emit "bbObjectDtor((BBOBJECT)o);"
- Else
- Emit "_" + superid + "_Delete((" + TransObject(TScopeDecl(classDecl.superClass.actual)) + ")o);"
- End If
- End Method
- Method TransFieldRef:String(decl:TFieldDecl, variable:String, exprType:TType = Null)
- Local s:String = variable
-
- Local ind:String = "->"
- If decl.scope And TClassDecl(decl.scope) And TClassDecl(decl.scope).IsStruct() Then
- Local exprIsStruct:Int = Not exprType Or (TObjectType(exprType) And TObjectType(exprType).classDecl.attrs & CLASS_STRUCT)
- If (exprIsStruct Or (exprType And Not IsPointerType(exprType))) And variable <> "o" Then
- If Not exprIsStruct Or (exprType And Not IsPointerType(exprType)) Then
- ind = "."
- End If
- End If
- End If
- If variable.StartsWith("*") Then
- variable = Bra(variable)
- End If
-
- ' Null test
- If opt_debug
- If TClassDecl(decl.scope) And TClassDecl(decl.scope).IsStruct() Then
- '
- Else
- variable = TransDebugNullObjectError(variable, TClassDecl(decl.scope))
- End If
- End If
- ' array.length
- If decl.scope And decl.scope.ident = "___Array" Then
- If decl.ident = "length" Then
- If TArrayType(exprType) And TArrayType(exprType).isStatic Then
- Return TArrayType(exprType).length
- Else
- Return Bra(variable + "->scales[0]")
- End If
- End If
- If decl.ident = "numberOfDimensions" Then
- Return Bra(variable + "->dims")
- End If
- If decl.ident = "sizeMinusHeader" Then
- Return Bra(variable + "->size")
- End If
- If decl.ident = "elementTypeEncoding" Then
- Return Bra(variable + "->type")
- End If
- End If
- ' string methods
- If decl.scope And decl.scope.ident = "String" Then
- If decl.ident = "length" Then
- 'If exprType._flags & TType.T_VAR Then
- ' Return Bra("(*" + variable + ")->length")
- 'Else
- If variable.StartsWith("&_s") Then
- Return Bra(variable[1..] + ".length")
- Else
- Return Bra(variable + "->length")
- End If
- 'End If
- End If
- End If
- 'If TObjectType(exprType) And (exprType._flags & TType.T_VAR) Then
- ' ' get the object from the pointer
- ' variable = Bra("*" + variable)
- 'End If
- If IsNumericType(decl.ty) Then
- s = variable + ind + decl.munged + " "
- Else If TStringType(decl.ty) Then
- s = variable + ind + decl.munged + " "
- Else If TObjectType(decl.ty) Then
- s = variable + ind + decl.munged + " "
- Else If IsPointerType(decl.ty, 0, TType.T_POINTER) Then
- s = variable + ind + decl.munged + " "
- Else If TFunctionPtrType(decl.ty) Then
- s = variable + ind + decl.munged + " "
- Else If TArrayType(decl.ty) Then
- s = variable + ind + decl.munged + " "
- Else If TEnumType(decl.ty) Then
- s = variable + ind + decl.munged + " "
- End If
- Return s
- End Method
- ' " _" + classDecl.actual.munged + "_" + decl.ident.ToLower(
- Method TransIfcArgs:String(funcDecl:TFuncDecl)
- Local args:String
- If Not funcDecl.IsSemanted() Then
- funcDecl.Semant()
- End If
- For Local i:Int=0 Until funcDecl.argDecls.Length
- Local arg:TArgDecl = funcDecl.argDecls[i]
- If args args:+","
- args:+ arg.ident + TransIfcType( arg.ty )
- If arg.init Then
- If TInvokeExpr(arg.init) Then
- args:+ "=" + Enquote(TInvokeExpr(arg.init).decl.munged)
- Else
- args:+ "=" + TransIfcConstExpr(arg.init)
- End If
- End If
- Next
- Return Bra(args)
- End Method
- Method EmitIfcClassFuncDecl(funcDecl:TFuncDecl)
- funcDecl.Semant
- Local func:String
- ' method / function
- If funcDecl.IsMethod() Or funcDecl.IsCTor() Then
- func :+ "-"
- Else
- func :+ "+"
- End If
- If funcDecl.attrs & FUNC_OPERATOR Then
- func :+ BmxEnquote(funcDecl.ident)
- Else
- func :+ funcDecl.ident
- End If
- If Not TNewDecl(funcDecl) Then
- func :+ TransIfcType(funcDecl.retType, funcDecl.ModuleScope().IsSuperStrict())
- End If
- ' function args
- func :+ TransIfcArgs(funcDecl)
- If funcDecl.attrs & DECL_FINAL Then
- func :+ "F"
- Else If funcDecl.attrs & DECL_ABSTRACT Then
- func :+ "A"
- End If
-
- If funcDecl.attrs & FUNC_OPERATOR Then
- func :+ "O"
- End If
-
- If funcDecl.attrs & DECL_PRIVATE Then
- func :+ "P"
- Else If funcDecl.attrs & DECL_PROTECTED Then
- func :+ "R"
- End If
-
- If funcDecl.attrs & DECL_API_STDCALL Then
- func :+ "W"
- End If
-
- If funcDecl.attrs & DECL_EXPORT Then
- func :+ "E"
- End If
- func :+ "="
- func :+ Enquote(funcDecl.munged)
- Emit func
- End Method
- Method EmitIfcFuncDecl(funcDecl:TFuncDecl)
- Local func:String
- func :+ funcDecl.ident
- ' ensure the function has been semanted
- funcDecl.Semant()
- func :+ TransIfcType(funcDecl.retType, funcDecl.ModuleScope().IsSuperStrict())
- ' function args
- func :+ TransIfcArgs(funcDecl)
- If funcDecl.attrs & DECL_API_STDCALL Then
- func :+ "W"
- End If
- func :+ "="
- func :+ Enquote(funcDecl.munged)
- If funcDecl.castTo Then
- func :+ ":" + funcDecl.castTo
- func :+ " " + funcDecl.munged + "("
- For Local i:Int = 0 Until funcDecl.argDecls.length
- If i Then
- func :+ ", "
- End If
- func :+ funcDecl.argDecls[i].castTo
- Next
- func :+ ")"
- End If
- Emit func
- End Method
- Method TransIfcConstExpr:String(expr:TExpr)
- If Not expr.exprType Then
- expr.Semant()
- End If
- If TStringType(expr.exprType) Then
- Return "$" + EscapeChars(BmxEnquote(expr.Eval()))
- EndIf
- If TArrayType(expr.exprType) Then
- Return Enquote("bbEmptyArray")
- End If
- If TFunctionPtrType(expr.exprType) Then
- If TCastExpr(expr) Then
- If TInvokeExpr(TCastExpr(expr).expr) Then
- Return Enquote(TInvokeExpr(TCastExpr(expr).expr).decl.munged)
- End If
- If TNullExpr(TCastExpr(expr).expr) Then
- Return Enquote("brl_blitz_NullFunctionError")
- End If
- End If
- InternalErr "TCTranslator.TransIfcConstExpr"
- End If
- If TObjectType(expr.exprType) Then
- If TCastExpr(expr) Then
- If TNullExpr(TCastExpr(expr).expr) Then
- Return Enquote("bbNullObject")
- End If
- End If
- End If
-
- If IsPointerType(expr.exprType, 0, TType.T_POINTER) Then
- If TCastExpr(expr) Then
- If TNullExpr(TCastExpr(expr).expr) Then
- Return "0"
- End If
- If TConstExpr(TCastExpr(expr).expr) Then
- Return TConstExpr(TCastExpr(expr).expr).value
- End If
- End If
- End If
- If IsNumericType(expr.exprType) Then
- Local s:String = expr.Eval()
- If Not s Then
- Return "0"
- Else
- If TDecimalType(expr.exprType) Then
- If s.StartsWith("1.#INF0000") Or s = "1e1000" Then
- s = "inf"
- Else If s.StartsWith("-1.#INF0000") Then
- s = "-inf"
- Else If s.StartsWith("-1.#IND0000") Then
- s = "nan"
- End If
- Return s + TransIfcType(expr.exprType)
- Else
- Return s
- End If
- End If
- EndIf
- If TEnumType(expr.exprType) Then
- If TCastExpr(expr) And TNullExpr(TCastExpr(expr).expr) Then
- Return TransValue(expr.exprType, Null)
- Else
- Return Expr.Eval()
- End If
- End If
- 'If TObjectType(expr.exprType) And TNullDecl(TObjectType(expr.exprType).classDecl) Then
- ' Return Enquote("bbNullObject")
- 'End If
- End Method
- Method EmitIfcConstDecl(constDecl:TConstDecl)
- Local c:String
- c = constDecl.ident + TransIfcType(constDecl.ty)
- If TExpr(constDecl.init) Then
- c:+ "=" + TransIfcConstExpr(TExpr(constDecl.init))
- End If
- Emit c
- End Method
- Method EmitIfcFieldDecl(fieldDecl:TFieldDecl)
-
- Local f:String
- If fieldDecl.IsReadOnly() Then
- f :+ "@"
- End If
- If fieldDecl.IsStatic() Then
- f :+ "~~"
- End If
-
- If Not f Then
- f :+ "."
- End If
- f :+ fieldDecl.ident + TransIfcType(fieldDecl.ty, fieldDecl.ModuleScope().IsSuperStrict())
- f :+ "&"
-
- If fieldDecl.IsPrivate() Then
- f :+ "`"
- Else If fieldDecl.IsProtected() Then
- f :+ "``"
- End If
- Emit f
- End Method
- Method EmitIfcClassDecl(classDecl:TClassDecl)
-
- Local head:String = classDecl.ident + "^"
- If classDecl.superClass Then
- Local superDecl:TClassDecl = classDecl.superClass
- head :+ superDecl.ident
- If superDecl.instArgs Then
- head :+ "<"
- Local s:String
- For Local ty:TType = EachIn superDecl.instArgs
- If s Then
- s :+ ","
- End If
- s :+ ty.ToString()
- Next
- head :+ s
- head :+ ">"
- End If
- Else
- head :+ "Null"
- End If
-
- If classDecl.implments Then
- head :+ "@"
- For Local i:Int = 0 Until classDecl.implments.length
- If i Then
- head :+ ","
- End If
- head :+ classDecl.implments[i].ident
- Next
- End If
-
- Emit head + "{", False
- 'PushMungScope
- BeginLocalScope
- If Not classDecl.templateSource Then
-
- ' const
- For Local cDecl:TConstDecl = EachIn classDecl.Decls()
- cDecl.Semant()
-
- EmitIfcConstDecl(cDecl)
- Next
-
- ' global
- For Local gDecl:TGlobalDecl = EachIn classDecl.Decls()
- gDecl.Semant()
-
- EmitIfcGlobalDecl(gDecl)
- Next
-
-
- ' field
- For Local fDecl:TFieldDecl = EachIn classDecl.Decls()
- fDecl.Semant()
-
- EmitIfcFieldDecl(fDecl)
- Next
- End If
- ' functions
- If Not classDecl.IsExtern() Then
-
- If Not classDecl.templateSource Then
- If Not (classDecl.attrs & CLASS_INTERFACE) And Not classDecl.IsStruct() And Not classHierarchyHasFunction(classDecl, "New") Then
- Emit "-New()=" + Enquote("_" + classDecl.munged + "_New")
- End If
- If classHierarchyHasFunction(classDecl, "Delete") Then
- Emit "-Delete()=" + Enquote("_" + classDecl.munged + "_Delete")
- End If
-
- For Local decl:TDecl=EachIn classDecl.Decls()
-
- Local fdecl:TFuncDecl=TFuncDecl( decl )
- If fdecl
- If Not equalsIfcBuiltInFunc(classDecl, fdecl) Then
- EmitIfcClassFuncDecl fdecl
- End If
- Continue
- EndIf
-
- Next
-
- End If
-
- Local flags:String
- If classDecl.IsAbstract() Then
- flags :+ "A"
- End If
-
- If classDecl.attrs & DECL_FINAL Then
- flags :+ "F"
- End If
- If classDecl.attrs & CLASS_INTERFACE Then
- flags :+ "I"
- Else If classDecl.IsStruct() Then
- flags :+ "S"
- End If
-
- If classDecl.IsPrivate() Then
- flags :+ "P"
- End If
-
- If classDecl.templateSource Then
- flags :+ "G"
- End If
-
- Local t:String = "}" + flags + "="
-
-
-
- If classDecl.templateSource Then
- Local s:String
- If classDecl.instArgs Then
- t :+ Enquote(classDecl.scope.munged + "|" + classDecl.munged)
- t :+ ",<"
- For Local ty:TType = EachIn classDecl.instArgs
- If s Then
- s :+ ","
- End If
- s :+ ty.ToString()
- Next
- Else
- t :+ Enquote(classDecl.scope.munged)
- t :+ ",<"
- s = "?"
- End If
-
- t :+ s + ">" + classDecl.templateSource.ToString()
- Else
- t :+ Enquote(classDecl.munged)
- End If
-
- Emit t, False
- Else
- For Local decl:TDecl=EachIn classDecl.Decls()
- Local fdecl:TFuncDecl=TFuncDecl( decl )
- If fdecl
- EmitIfcClassFuncDecl fdecl
- Continue
- EndIf
- Next
-
- Local flags:String = "E"
-
- If classDecl.IsInterface() Then
- flags :+ "I"
- Else If classDecl.IsStruct() Then
- flags :+ "S"
- End If
-
- If classDecl.attrs & DECL_API_STDCALL Then
- flags :+ "W"
- End If
- Emit "}" + flags + "=0", False
- End If
- 'PopMungScope
- EndLocalScope
- End Method
- Method EmitIfcGlobalDecl(globalDecl:TGlobalDecl)
- globalDecl.Semant
- Local g:String = globalDecl.ident
- g:+ TransIfcType(globalDecl.ty, globalDecl.ModuleScope().IsSuperStrict())
-
- g:+ "&"
- If globalDecl.IsPrivate() Then
- g :+ "`"
- Else If globalDecl.IsProtected() Then
- g :+ "``"
- End If
- g :+ "="
- g :+ "mem:p("
- If TFunctionPtrType(globalDecl.ty) Then
- g :+ Enquote(TFunctionPtrType(globalDecl.ty).func.munged)
- Else
- g :+ Enquote(globalDecl.munged)
- End If
- g :+ ")"
- Emit g
- End Method
- Method EmitIfcEnumDecl(enumdecl:TEnumDecl)
- enumDecl.Semant
-
- Local e:String = enumDecl.ident + "\" + TransIfcType(enumDecl.ty)
- Emit e + "{", False
-
- For Local val:TEnumValueDecl = EachIn enumDecl.values
- Emit val.ident + "=" + val.Value()
- Next
-
- Local flags:String
- If enumDecl.isFlags Then
- flags = "F"
- End If
-
- Emit "}" + flags + "=" + Enquote(enumDecl.munged), False
- End Method
-
- Method EmitModuleInclude(moduleDecl:TModuleDecl, included:TMap = Null)
- If moduleDecl.filepath Then
- ' a module import
- If FileType(moduleDecl.filepath) = FILETYPE_DIR Or (opt_ismain And moduleDecl.ident = opt_modulename) Then
- Local inc:String = ModuleHeaderFromIdent(moduleDecl.ident, True)
- If Not included Or (included And Not included.Contains(inc)) Then
- Emit "#include <" + inc + ">"
- If included Then
- included.Insert(inc, inc)
- End If
- End If
- Else
- ' a file import...
- Local inc:String = FileHeaderFromFile(moduleDecl, False)
- If Not included Or (included And Not included.Contains(inc)) Then
- Emit "#include ~q" + inc + "~q"
- If included Then
- included.Insert(inc, inc)
- End If
- End If
- End If
- ' DebugLog moduleDecl.filepath
- End If
- End Method
- Method EmitModuleInit(moduleDecl:TModuleDecl)
- If moduleDecl.filepath Then
- ' a module import
- If FileType(moduleDecl.filepath) = FILETYPE_DIR Then
- Emit MungModuleName(moduleDecl) + "();"
- Else
- ' maybe a file import...
- Emit MungImportFromFile(moduleDecl) + "();"
- End If
- End If
- End Method
- Method EmitIncBinFile(ib:TIncbin)
- If FileType(ib.path) = FILETYPE_FILE Then
- If Not opt_legacy_incbin Then
- Local ident:String = _appInstance.munged + "_" + ib.id
- Emit "INCBIN(" + ident + ", ~q" + ib.path + "~q);"
- Else
- Local ident:String = _appInstance.munged + "_ib_" + ib.id
- Local buf:Byte[] = LoadByteArray(ib.path)
- ib.length = buf.length
- Emit "unsigned char " + ident + "[] = {"
- Local sb:TStringBuffer = New TStringBuffer
- Local hx:Short[2]
- Local LINES:Int
- Local count:Int
- For Local i:Int = 0 Until buf.length
- Local val:Int = buf[i]
- For Local k:Int=1 To 0 Step -1
- Local n:Int=(val&15)+48
- If n>57 n:+39
- hx[k]=n
- val:Shr 4
- Next
- sb.Append("0x").AppendShorts( hx,2 )
- sb.Append(",")
-
- count :+ 5
- If count > 80 Then
- sb.Append("~n")
- count = 0
- LINES :+ 1
- End If
-
- If LINES > 100 Then
- Emit sb.ToString()
- sb.SetLength(0)
- LINES = 0
- End If
-
- Next
- Emit sb.ToString()
- Emit "};"
- End If
- End If
- End Method
- Method TransHeader(app:TAppDecl)
- SetOutput("head")
- _app = app
- prefix = app.GetPathPrefix()
- ' TODO
- If Not opt_apptype Then
- app.mainFunc.munged="bb_localmain"
- Else
- app.mainFunc.munged="bb_main"
- End If
- ' track what's been included so far - avoid duplicates
- Local included:TMap = New TMap
- For Local decl:TModuleDecl=EachIn app.imported.Values()
- For Local mdecl:TDecl=EachIn decl.imported.Values()
- MungDecl mdecl
- 'skip mdecls we are not interested in
- If Not TModuleDecl(mdecl) Then Continue
- If app.mainModule = mdecl Then Continue
- If mdecl.ident = "brl.classes" Then Continue
- If mdecl.ident = "brl.blitzkeywords" Then Continue
- EmitModuleInclude(TModuleDecl(mdecl), included)
- Next
- Next
-
- For Local header:String=EachIn app.headers
- Emit "#include ~q../" + header + "~q"
- Next
- Emit "int " + app.munged + "();"
- For Local decl:TDecl=EachIn app.Semanted()
- If decl.declImported And decl.munged Continue
- MungDecl decl
- Local cdecl:TClassDecl=TClassDecl( decl )
- If Not cdecl Continue
- ' mung, but don't emit
- ' Emit prefix + decl.munged+";"
- 'PushMungScope
- funcMungs = New TMap
- BeginLocalScope
- For Local decl:TDecl=EachIn cdecl.Semanted()
- MungDecl decl
-
- cdecl.SemantParts()
- Next
- EndLocalScope
- 'PopMungScope
- Next
- ' forward declarations
- For Local decl:TClassDecl=EachIn app.Semanted()
- If decl.declImported Or (decl.IsExtern() And Not decl.IsStruct()) Continue
- If Not decl.IsStruct()
- Emit "struct " + decl.munged + "_obj;"
- Else
- Emit "struct " + decl.munged + ";"
- End If
- If decl.IsInterface() Then
- Emit "extern const struct BBInterface " + decl.munged + "_ifc;"
- End If
- Next
- 'prototypes/header! - structs first
- For Local decl:TDecl=EachIn app.Semanted()
- If decl.declImported Continue
- Local cdecl:TClassDecl=TClassDecl( decl )
- If cdecl
- If cdecl.IsStruct() Then
- EmitStructClassProto cdecl
- End If
- EndIf
- Next
-
- ' prototypes/header - typedefs
- For Local cdecl:TClassDecl=EachIn app.Semanted()
- If cdecl.declImported Continue
-
- If Not cdecl.IsStruct() And cdecl.IsExtern() Then
- EmitExternClassProtoTypedef(cdecl)
- End If
- Next
- 'prototypes/header!
- For Local decl:TDecl=EachIn app.Semanted()
- If decl.declImported Continue
- Local gdecl:TGlobalDecl=TGlobalDecl( decl )
- If gdecl
- MungDecl gdecl
-
- If Not gdecl.IsPrivate() Then
- If Not TFunctionPtrType(gdecl.ty) Then
- Emit "extern "+TransThreadedGlobal(gdecl)+TransRefType( gdecl.ty, "" )+" "+gdecl.munged+";" 'forward reference...
- Else
- If Not TFunctionPtrType(gdecl.ty).func.noCastGen Then
- ' generate function pointer refs if we haven't been told not to
- ' If Not gdecl.IsExtern() Then
- Emit "extern " + TransThreadedGlobal(gdecl) + TransRefType( gdecl.ty, gdecl.munged )+";" 'forward reference...
- ' End If
- End If
- End If
- End If
- Continue
- EndIf
- Local fdecl:TFuncDecl=TFuncDecl( decl )
- If fdecl' And Not fdecl.IsExtern()
- ' don't include the main function - it's handled separately
- If fdecl = app.mainFunc Then
- Continue
- End If
- EmitGDBDebug(fdecl)
- EmitFuncDecl( fdecl, True)
- Continue
- EndIf
- Local cdecl:TClassDecl=TClassDecl( decl )
- If cdecl
- If Not cdecl.IsStruct() Then
- If Not cdecl.IsExtern()
- EmitClassProto cdecl
- Else
- EmitExternClassProto cdecl
- End If
- 'Else
- ' EmitStructClassProto cdecl
- End If
- 'Continue
- EndIf
- Local edecl:TEnumDecl = TEnumDecl( decl )
- If edecl Then
- EmitEnumProto edecl
- Continue
- End If
- Next
- End Method
- Method IncBinRequiresRebuild:Int(file:String, incbins:TList)
- ' file doesn't exist?
- If Not FileType(file) Then
- Return True
- End If
- Local timestamp:Int = FileTime(file)
- ' file exists... read header and compare names
- ' read lines until "// ----"
- ' TODO
- Local files:TList = New TList
- Local hashes:TMap = New TMap
- Local stream:TStream = ReadFile(file)
- While True
- Local s:String = ReadLine(stream)
- If Not s.StartsWith("// ") Or s.StartsWith("// ----") Then
- Exit
- End If
- Local ind:Int = s.Find("// FILE : ")
- If ind = 0 Then
- Local line:String = s[10..]
-
- Local parts:String[] = line.Split("~t")
- If parts.length = 1 Then
- Return True
- End If
-
- Local filename:String = parts[0].Replace("~q","")
- Local fileHash:String = parts[1]
- files.AddLast(filename)
- hashes.Insert(filename, fileHash)
- End If
- Wend
- stream.Close()
- ' different number of files?
- If files.Count() <> incbins.Count() Then
- Return True
- End If
- ' different file names?
- Local count:Int
- For Local s:String = EachIn files
- For Local ib:TIncbin = EachIn incbins
- If s = ib.file Then
- count :+ 1
- Exit
- End If
- Next
- Next
- If count <> files.count() Then
- Return True
- End If
- count = 0
- For Local ib:TIncbin = EachIn incbins
- For Local s:String = EachIn files
- If s = ib.file Then
- count :+ 1
- Exit
- End If
- Next
- Next
- If count <> incbins.count() Then
- Return True
- End If
- For Local ib:TIncbin = EachIn incbins
- If timestamp < FileTime(ib.path) Then
- Return True
- End If
-
- Local fileHash:String = String(hashes.ValueForKey(ib.file))
- If Not fileHash Then
- Return True
- End If
-
- If fileHash <> CalculateFileHash(ib.path) Then
- Return True
- End If
- ' set the length, as we will need this later if we aren't loading the files now.
- ib.length = FileSize(ib.path)
- Next
- Return False
- End Method
- Method TransIncBin(app:TAppDecl)
- If app.incbins.Count() > 0 Then
- SetOutput("incbin")
- Local mung:String = FileMung(False)
- Local name:String = StripAll(app.mainModule.filepath)
- Local file:String
- If opt_legacy_incbin Then
- file = "incbin.c"
- Else
- file = "incbin2.c"
- End If
- Local filepath:String = OutputFilePath(opt_filepath, mung, file)
- If IncBinRequiresRebuild(filepath, app.incbins) Then
- If Not opt_legacy_incbin Then
- Emit "#define INCBIN_PREFIX _ib"
- Emit "#define INCBIN_STYLE INCBIN_STYLE_SNAKE"
- Emit "#include ~qbrl.mod/blitz.mod/incbin/incbin.h~q"
- End If
- app.genIncBinHeader = True
- For Local ib:TIncbin = EachIn app.incbins
- Local fileHash:String = CalculateFileHash(ib.path)
- Emit "// FILE : " + Enquote(ib.file) + "~t" + fileHash
- Next
- Emit "// ----"
- For Local ib:TIncbin = EachIn app.incbins
- EmitIncBinFile(ib)
- Next
- End If
- SetOutput("pre_source")
- End If
- End Method
- Method TransGlobalInit(decl:TGlobalDecl)
- If TFunctionPtrType(decl.ty) Then
- If TInvokeExpr(decl.init) And Not TInvokeExpr(decl.init).invokedWithBraces Then
- Emit TransGlobal( decl )+"="+TInvokeExpr(decl.init).decl.munged + ";"
- Else
- Emit TransGlobal( decl )+"="+decl.init.Trans()+";"
- End If
- Else
- If Not decl.funcGlobal Then
- If TObjectType(decl.ty) And Not TObjectType(decl.ty).classDecl.IsStruct() Then
- Emit TransGlobal( decl )+"="+Bra(TransObject(TObjectType(decl.ty).classDecl))+decl.init.Trans()+";"
- Else
- Emit TransGlobal( decl )+"="+decl.init.Trans()+";"
- End If
- End If
- End If
- End Method
- Method TransSource(app:TAppDecl)
- SetOutput("pre_source")
- ' include our header
- EmitModuleInclude(app.mainModule)
- ' incbins
- TransIncBin(app)
- SetOutput("source")
- ' nested type forward declarations
- For Local decl:TClassDecl=EachIn app.Semanted()
- For Local cdecl:TClassDecl = EachIn decl._decls
- MungDecl decl
- MungDecl cdecl
- If cdecl.declImported Or (cdecl.IsExtern() And Not cdecl.IsStruct()) Continue
- If Not cdecl.IsStruct()
- Emit "struct " + cdecl.munged + "_obj;"
- Else
- Emit "struct " + cdecl.munged + ";"
- End If
- If cdecl.IsInterface() Then
- Emit "extern const struct BBInterface " + cdecl.munged + "_ifc;"
- End If
- Next
- Next
- ' Private Global declarations
- ' since we don't declare them in the header, they need to be near the top of the source
- For Local decl:TDecl=EachIn app.Semanted()
- If decl.declImported Continue
- Local gdecl:TGlobalDecl=TGlobalDecl( decl )
- If gdecl And gdecl.IsPrivate() Then
- If Not TFunctionPtrType(gdecl.ty) Then
- If TConstExpr(gdecl.init) Then
- Emit TransRefType( gdecl.ty, "WW" )+" "+TransGlobalDecl(gdecl)+";"
- gdecl.inited = True
- Else
- If Not gdecl.IsExtern() Then
- Emit TransRefType( gdecl.ty, "WW" )+" "+gdecl.munged+";"
- Else
- ' delcare in source for any references to it locally in this module
-
- Emit "extern "+ TransThreadedGlobal(gdecl) +TransRefType( gdecl.ty, "WW" )+" "+gdecl.munged+";"
- End If
- End If
- Else
- If Not gdecl.IsExtern() Then
- Emit TransRefType( gdecl.ty, gdecl.munged ) + ";"
- EndIf
- End If
- Continue
- EndIf
-
- Next
- For Local gdecl:TGlobalDecl=EachIn app.SemantedGlobals
- If gdecl And gdecl.funcGlobal Then
- MungDecl gdecl
- If Not TFunctionPtrType(gdecl.ty) Then
- Emit "static " + TransThreadedGlobal(gdecl) + TransRefType( gdecl.ty, "WW" )+" "+gdecl.munged+";"
- Else
- Emit "static " + TransThreadedGlobal(gdecl) + TransRefType( gdecl.ty, gdecl.munged ) + ";"
- End If
- Continue
- End If
- Next
- 'definitions!
- For Local decl:TDecl=EachIn app.Semanted()
- If decl.declImported Continue
- Local gdecl:TGlobalDecl=TGlobalDecl( decl )
- If gdecl
- If gdecl.IsPrivate() Continue
-
- If Not TFunctionPtrType(gdecl.ty) And Not gdecl.IsPrivate() Then
- If TConstExpr(gdecl.init) Then
- Emit TransThreadedGlobal(gdecl) + TransRefType( gdecl.ty, "WW" )+" "+TransGlobalDecl(gdecl)+";"
- gdecl.inited = True
- Else
- If Not gdecl.IsExtern() Then
- If TObjectType(gdecl.ty) Then
- Emit TransRefType( gdecl.ty, "WW" )+" "+gdecl.munged+ "=" + Bra(TransObject(TObjectType(gdecl.ty).classDecl)) + TransValue(gdecl.ty, "") + ";"
- Else
- Emit TransRefType( gdecl.ty, "WW" )+" "+gdecl.munged+ "=" + TransValue(gdecl.ty, "") + ";"
- End If
- End If
- End If
- Else
- If TFunctionPtrType(gdecl.ty) And Not gdecl.IsExtern() Then
- Emit TransRefType( gdecl.ty, gdecl.munged ) + ";"
- End If
- End If
- Continue
- EndIf
- Local fdecl:TFuncDecl=TFuncDecl( decl )
- If fdecl And Not fdecl.IsExtern()
- ' don't include the main function - it's handled separately
- If fdecl = app.mainFunc Then
- Continue
- End If
- EmitGDBDebug(fdecl)
- EmitFuncDecl fdecl
- Continue
- EndIf
- Local cdecl:TClassDecl=TClassDecl( decl )
- If cdecl
- EmitGDBDebug(cdecl)
- EmitClassDecl cdecl
- Continue
- EndIf
-
- Local edecl:TEnumDecl = TEnumDecl( decl )
- If edecl Then
- EmitEnumDecl edecl
- Continue
- End If
- Next
- ' emit nested functions/classes for localmain
- ' emit nested protos
- For Local fdecl:TFuncDecl = EachIn app.mainFunc._decls
- EmitFuncDecl(fdecl, True)
- Next
-
- ' emit nested bodies
- For Local fdecl:TFuncDecl = EachIn app.mainFunc._decls
- EmitFuncDecl(fdecl, False)
- Next
- ' incbin decls
- For Local ib:TIncbin = EachIn app.incbins
- If opt_legacy_incbin Then
- Emit "extern unsigned char * " + app.munged + "_ib_" + ib.id + ";"
- Else
- Emit "extern const unsigned char * " + ib.GeneratedDataName(app) + ";"
- Emit "extern const unsigned int " + ib.GeneratedSizeName(app) + ";"
- End If
- Next
- ' coverage
- Local covCount:Int
- If opt_coverage Then
- Local id:Int
- For Local file:String = EachIn coverageFileInfo.Keys()
- Local covFile:TCoverageLineInfo = TCoverageLineInfo(coverageFileInfo.ValueForKey(file))
- Local t:String
- Emit "static int coverage_lines_" + id + "[] = {"
- For Local i:Int = 0 Until covFile.lines.Length
- If i And i Mod 40 = 0 Then
- If i Then
- t :+ ","
- End If
- Emit t
- t = ""
- Else
- If i Then
- t :+ ","
- End If
- End If
- t :+ covFile.lines[i]
- Next
- If t Then
- Emit t
- End If
- Emit "};"
- Emit "static BBCoverageFunctionInfo coverage_funcs_" + id + "[] = {"
- Local covFuncFile:TCoverageFunctionLineInfo = TCoverageFunctionLineInfo(coverageFunctionFileInfo.ValueForKey(file))
- For Local i:Int = 0 Until covFuncFile.funcs.Length
- Emit "{ " + Enquote(covFuncFile.funcs[i].name) + ", " + covFuncFile.funcs[i].line + " },"
- Next
- Emit "};"
- id :+ 1
- Next
- covCount = id
- If id Then
- id = 0
- Emit "static BBCoverageFileInfo coverage_files[] = {"
- For Local file:String = EachIn coverageFileInfo.Keys()
- Local covFile:TCoverageLineInfo = TCoverageLineInfo(coverageFileInfo.ValueForKey(file))
-
- Emit "{"
- Emit Enquote(file) + ","
- Emit "coverage_lines_" + id + ","
- Emit "sizeof(coverage_lines_" + id + ") / sizeof(coverage_lines_" + id + "[0]),"
- Emit "NULL,"
- Emit "coverage_funcs_" + id + ","
- Emit "sizeof(coverage_funcs_" + id + ") / sizeof(coverage_funcs_" + id + "[0]),"
- Emit "NULL,"
- Emit "},"
- id :+ 1
- Next
- Emit "{ NULL, NULL, 0, NULL, NULL, 0, NULL }"
- Emit "};"
- End If
- End If
- Emit "static int " + app.munged + "_inited" + " = 0;"
- Emit "int " + app.munged + "(){"
- ' initialise stuff
- Emit "if (!" + app.munged + "_inited) {"
- Emit app.munged + "_inited = 1;"
- ' add global roots
- Local first:TGlobalDecl
- Local last:TGlobalDecl
-
- For Local decl:TGlobalDecl=EachIn app.semantedGlobals
- If decl.declImported Continue
- decl.Semant
- If Not first Then
- first = decl
- End If
-
- last = decl
- Next
- If first Then
- Emit "GC_add_roots(&" + first.munged + ", &" + last.munged + " + 1);"
- End If
-
- ' threaded global scope assignments
- For Local decl:TDecl=EachIn app.Semanted()
- If decl.declImported Continue
- Local cdecl:TClassDecl=TClassDecl( decl )
- If cdecl
- EmitClassThreadedGlobalDebugInit(cdecl)
- End If
- Next
- ' register incbins
- For Local ib:TIncbin = EachIn app.incbins
- If opt_legacy_incbin Then
- Emit "bbIncbinAdd((BBString*)&" + StringConstId(ib.file) + ",&" + app.munged + "_ib_" + ib.id + "," + ib.length + ");"
- Else
- Emit "bbIncbinAdd((BBString*)&" + StringConstId(ib.file) + ",&" + ib.GeneratedDataName(app) + "," + ib.GeneratedSizeName(app) + ");"
- End If
- Next
-
- Local importOnce:TMap = New TMap
-
- ' call any imported mod inits
- For Local decl:TModuleDecl=EachIn app.imported.Values()
- For Local mdecl:TDecl=EachIn decl.imported.Values()
- If TModuleDecl(mdecl) And app.mainModule <> mdecl And mdecl.ident <> "brl.classes" And mdecl.ident <> "brl.blitzkeywords" Then
- If Not importOnce.Contains(mdecl.ident) Then
- EmitModuleInit(TModuleDecl(mdecl))
- importOnce.Insert(mdecl.ident, "")
- End If
- End If
- Next
- Next
- ' initialise enums
- For Local decl:TEnumDecl = EachIn app.Semanted()
- If decl.declImported Continue
-
- Emit decl.munged + "_BBEnum_impl = (BBEnum *)&" + decl.munged + "_BBEnum;"
- Next
- ' initialise coverage
- If opt_coverage And covCount Then
- Emit "bbCoverageRegisterFile(coverage_files);"
- End If
- ' register types
- For Local decl:TDecl=EachIn app.Semanted()
- If decl.declImported Continue
- Local cdecl:TClassDecl=TClassDecl( decl )
- If cdecl And Not cdecl.IsExtern() And Not cdecl.args
- If Not cdecl.IsInterface() Then
- If Not cdecl.IsStruct() Then
- Emit "bbObjectRegisterType((BBCLASS)&" + cdecl.munged + ");"
- Else
- Emit "bbObjectRegisterStruct((BBDebugScope *)&" + cdecl.munged + "_scope);"
- End If
- Else
- Emit "bbObjectRegisterInterface((BBInterface *)&" + cdecl.munged + "_ifc);"
- End If
- Continue
- EndIf
- Local edecl:TEnumDecl = TEnumDecl( decl )
- If edecl Then
- Emit "bbEnumRegister((BBEnum *)" + decl.munged + "_BBEnum_impl, (BBDebugScope *)&" + edecl.munged + "_scope);"
- End If
- Next
- '
-
- ' register files
- If opt_debug Then
- For Local Hash:String = EachIn fileRegister.Keys()
- Local file:String = String(fileRegister.ValueForKey(Hash))
- file = file.Replace("\", "\\")
- Emit "bbRegisterSource(" + Hash + ", ~q" + file + "~q);"
- Next
- End If
- ' defdata init
- If Not app.dataDefs.IsEmpty() Then
- Emit "_defDataOffset = &_defData;"
- End If
- ' initialise globals
- For Local decl:TGlobalDecl=EachIn app.semantedGlobals
- If decl.declImported Continue
-
- decl.Semant
-
- If decl.scope And TClassDecl(decl.scope) And Not TClassDecl(decl.scope).IsStruct() Then
- Emit TransGlobal( decl )+"="+TransValue(decl.ty, Null)+";"
- End If
- Next
- ' initialise globals
- For Local decl:TGlobalDecl=EachIn app.semantedGlobals
- If decl.declImported Continue
- 'decl.Semant
- ' TODO : what about OnDebugStop etc, who have no init ?
- If decl.init And Not (decl.attrs & DECL_INITONLY) Then
- If decl.scope And TClassDecl(decl.scope) Then
- ' class global inits need to be generated in the correct order.
- ' only generate global inits if the parent class hasn't already been processed,
- ' otherwise, we will skip this global as it should already have been generated.
- If Not TClassDecl(decl.scope).globInit Then
-
- TClassDecl(decl.scope).globInit = True
-
- For Local gdecl:TGlobalDecl = EachIn decl.scope._decls
-
- If gdecl.declImported Continue
-
- gdecl.Semant
-
- If gdecl.init And Not (gdecl.attrs & DECL_INITONLY) Then
- TransGlobalInit(gdecl)
- End If
- Next
- End If
-
- Else
- TransGlobalInit(decl)
- End If
- End If
- Next
- ' now do the local main stuff
- app.mainFunc.Semant()
- EmitLocalDeclarations(app.mainFunc)
- EmitBlock app.mainFunc
- Emit "}"
- Emit "return 0;"
- Emit "}"
- ' redirect string generation to the def data section of the source
- SetOutput("def_data")
- ' defdata
- EmitDefDataArray(app)
-
- ' redirect string generation to the top of the source
- SetOutput("pre_source")
- ' strings
- ' generate sized structs
- Local sizes:TIntMap = New TIntMap
- For Local s:String = EachIn app.stringConsts.Keys()
- If s Then
- Local key:TStringConst = TStringConst(app.stringConsts.ValueForKey(s))
- If key.used > 0 Then
- If Not sizes.Contains(s.length) Then
- Emit "struct BBString_" + s.length + "{BBClass_String* clas;BBULONG hash;int length;BBChar buf[" + s.length + "];};"
- sizes.Insert(s.length, "")
- End If
- End If
- End If
- Next
-
- For Local s:String = EachIn app.stringConsts.Keys()
- If s Then
- Local key:TStringConst = TStringConst(app.stringConsts.ValueForKey(s))
- If key.used > 0 Then
-
- Emit "static struct BBString_" + s.length + " " + key.id + "={"
- Emit "&bbStringClass,"
- Emit bmx_gen_hash(s) + ","
- Emit s.length + ","
- Local t:String = "{"
- For Local i:Int = 0 Until s.length
- If i Then
- t:+ ","
- End If
- t:+ s[i]
- If i And Not (i Mod 16) Then
- Emit t
- t = ""
- End If
- Next
- Emit t + "}"
- Emit "};"
- End If
- End If
- Next
-
- ' scope defs
- If Not app.scopedefs.IsEmpty() Then
- For Local val:String = EachIn app.scopedefs.Keys()
- Local i:Int = val.ToInt()
- Emit "struct BBDebugScope_" + i + "{int kind; const char *name; BBDebugDecl decls[" + (i + 1) + "]; };"
- Next
- End If
- End Method
-
- Method EmitDefDataArray(app:TAppDecl)
- If Not app.dataDefs.IsEmpty() Then
- '
- Emit "static struct bbDataDef * _defDataOffset;"
- Emit "static struct bbDataDef _defData[" + TDefDataDecl.count + "]={"
-
- For Local decl:TDefDataDecl = EachIn app.dataDefs
- EmitDefData(decl)
- Next
-
- Emit "};"
- End If
- End Method
- Method EmitDefData(decl:TDefDataDecl)
- For Local i:Int = 0 Until decl.data.length
- Local expr:TExpr = decl.data[i]
-
- Emit "{"
-
- Emit TransDefDataType(expr.exprType) + ","
-
- Emit "{"
- Emit "." + TransDefDataUnionType(expr.exprType) + " = " + expr.Trans()
- Emit "}"
-
- Emit "},"
- Next
- End Method
- Method EmitIfcImports(impMod:TModuleDecl, processed:TMap)
- For Local decl:TDecl=EachIn impMod.imported.Values()
- Local mdecl:TModuleDecl=TModuleDecl( decl )
- If mdecl And mdecl.ident <> "brl.classes" And mdecl.ident <> "brl.blitzkeywords" Then
- If mdecl.filepath.EndsWith(".bmx")
- If _appInstance.mainModule<>mdecl
- EmitIfcImports(mdecl, processed)
- For Local s:String = EachIn mdecl.fileImports
- If Not processed.Contains("XX" + s + "XX") Then
- Emit "import " + BmxEnquote(s)
- processed.Insert("XX" + s + "XX", "")
- End If
- Next
- End If
- Else
- If Not processed.Contains(mdecl.ident)
- Emit "import " + mdecl.ident
- processed.Insert(mdecl.ident, "")
- End If
- End If
- End If
- Next
- End Method
- Method EmitIfcStructImports(impMod:TModuleDecl, processed:TMap)
- For Local decl:TDecl=EachIn impMod.imported.Values()
- Local mdecl:TModuleDecl=TModuleDecl( decl )
- If mdecl Then
- If mdecl.filepath.EndsWith(".bmx") And _appInstance.mainModule<>mdecl And Not processed.Contains(mdecl)
- EmitIfcStructImports(mdecl, processed)
- processed.Insert(mdecl, mdecl)
- For Local decl:TDecl=EachIn mdecl._decls
- decl.Semant
-
- ' consts
- Local cdecl:TConstDecl=TConstDecl( decl )
- If cdecl
- EmitIfcConstDecl(cdecl)
- Continue
- End If
- ' classes
- Local tdecl:TClassDecl=TClassDecl( decl )
- If tdecl
- EmitIfcClassDecl(tdecl)
- Continue
- EndIf
- ' functions
- Local fdecl:TFuncDecl=TFuncDecl( decl )
- If fdecl And fdecl <> _appInstance.mainFunc Then
- EmitIfcFuncDecl(fdecl)
- Continue
- End If
- ' globals
- Local gdecl:TGlobalDecl=TGlobalDecl( decl )
- If gdecl
- EmitIfcGlobalDecl(gdecl)
- Continue
- End If
- ' enums
- Local edecl:TEnumDecl=TEnumDecl( decl )
- If edecl
- EmitIfcEnumDecl(edecl)
- Continue
- EndIf
- Next
- End If
- End If
- Next
- End Method
- Method FileHeaderFromFile:String(mdecl:TModuleDecl, includePath:Int = False)
- Local name:String = StripAll(mdecl.filepath)
- Local dir:String = ExtractDir(mdecl.filePath)
- Local file:String = name + ".bmx" + FileMung(opt_apptype And (Not mdecl.declImported)) + ".h"
- If mdecl.relPath Then
- Local dir:String = ExtractDir(mdecl.relPath)
- If dir Then
- file = "../" + dir + "/.bmx/" + file
- End If
- End If
- Return file
- End Method
- Method MungImportFromFile:String(mdecl:TModuleDecl)
- Local result:String
- If opt_buildtype <> BUILDTYPE_MODULE Then
- Local dir:String = ExtractDir(mdecl.filepath).ToLower()
- dir = dir[dir.findLast("/") + 1..]
- If dir.EndsWith(".mod") Then
- dir = dir.Replace(".mod", "")
- End If
- Local file:String = StripDir(mdecl.filepath).ToLower()
- result = "_bb_" + dir + "_" + StripExt(file)
- Else
- result = "_bb_" + mdecl.ident
- End If
- 'return with all non-allowed chars (like "-" or " ") removed
- Return TStringHelper.Sanitize(result)
- End Method
- Method TransInterface(app:TAppDecl)
- SetOutput("interface")
- If app.mainModule.IsSuperStrict() Then
- Emit "superstrict"
- End If
- ' module info
- For Local info:String = EachIn app.mainModule.modInfo
- Emit "ModuleInfo " + BmxEnquote(info)
- Next
- ' module pragmas
- For Local pragma:String = EachIn app.mainModule.pragmas
- Emit "#pragma " + BmxEnquote(pragma)
- Next
- Local processed:TMap = New TMap
- ' module imports
- For Local decl:TDecl=EachIn app.mainModule.imported.Values()
- Local mdecl:TModuleDecl=TModuleDecl( decl )
- If mdecl Then
- If mdecl.IsActualModule() Then
- Emit "import " + mdecl.ident
- processed.Insert(mdecl.ident, "")
- Else If Not opt_ismain And mdecl.filepath.EndsWith(".bmx") And app.mainModule<>mdecl
- Local file:String = StripDir(mdecl.filepath)
- If mdecl.relPath Then
- Local dir:String = ExtractDir(mdecl.relPath)
- If dir Then
- file = dir + "/" + file
- End If
- End If
- If Not processed.Contains(file) Then
- Emit "import " + Enquote(file)
- processed.Insert(file, "")
- End If
- End If
- End If
- Next
- ' module imports from other files?
- If opt_buildtype = BUILDTYPE_MODULE And opt_ismain Then
- EmitIfcImports(app.mainModule, processed)
- End If
- ' other imports
- For Local s:String = EachIn app.fileImports
- Emit "import " + BmxEnquote(s)
- Next
- processed = New TMap
- ' imported module structure (consts, classes, functions, etc)
- If opt_buildtype = BUILDTYPE_MODULE And opt_ismain Then
- EmitIfcStructImports(app.mainModule, processed)
- End If
- ' consts
- For Local decl:TDecl=EachIn app.Semanted()
- If decl.IsPrivate() Continue
- Local cdecl:TConstDecl=TConstDecl( decl )
- If cdecl And Not cdecl.declImported
- EmitIfcConstDecl(cdecl)
- End If
- Next
- ' classes
- For Local decl:TDecl=EachIn app.Semanted()
- Local cdecl:TClassDecl=TClassDecl( decl )
-
- If cdecl And cdecl.IsPrivate() And (Not cdecl.IsStruct() Or (cdecl.IsStruct() And Not cdecl.exposed)) Then
- Continue
- End If
-
- If cdecl And Not cdecl.declImported
- EmitIfcClassDecl(cdecl)
- EndIf
- Next
- ' functions
- For Local decl:TDecl=EachIn app.Semanted()
- If decl.IsPrivate() Continue
- Local fdecl:TFuncDecl=TFuncDecl( decl )
- If fdecl And fdecl <> app.mainFunc And Not fdecl.declImported Then
- EmitIfcFuncDecl(fdecl)
- End If
- Next
- ' globals
- For Local decl:TDecl=EachIn app.Semanted()
- If decl.IsPrivate() Continue
- Local gdecl:TGlobalDecl=TGlobalDecl( decl )
- If gdecl And Not gdecl.declImported
- EmitIfcGlobalDecl(gdecl)
- End If
- Next
-
- ' enums
- For Local decl:TDecl=EachIn app.Semanted()
- If decl.IsPrivate() Continue
-
- Local edecl:TEnumDecl=TEnumDecl( decl )
- If edecl And Not edecl.declImported
- EmitIfcEnumDecl(edecl)
- End If
- Next
- End Method
-
- Method TransDef(app:TAppDecl)
- SetOutput("def")
- Emit "LIBRARY " + StripExt(StripDir(opt_filepath))
- Emit "EXPORTS"
-
- For Local decl:TFuncDecl=EachIn app.exportDefs
- Emit "~t" + TransExportDef(decl, opt_arch = "x86")
- Next
- Emit "~n"
- End Method
- Method TransApp( app:TAppDecl )
- If app.mainModule.IsSuperStrict()
- opt_issuperstrict = True
- End If
- TransHeader(app)
- TransSource(app)
- TransInterface(app)
- If opt_makelib Then
- If opt_def And opt_apptype Then
- TransDef(app)
- End If
- End If
-
- End Method
-
- End Type
|