public CSTranslationClass TranslateBHAV(StructuredBHAV bhav) { var csClass = new CSTranslationClass(); csClass.ClassName = CSTranslationContext.FormatName(bhav.Source.ChunkLabel) + "_" + bhav.Source.ChunkID; csClass.Structure = bhav; csClass.InlineFunction = !bhav.Yields; csClass.ArgCount = Math.Max(4, (int)bhav.Source.Args); //possible to make this tighter by analysing func Context.CurrentBHAV = bhav.Source; Context.CurrentClass = csClass; csClass.Instructions = bhav.Instructions.ToDictionary(x => x.Key, x => { var inst = x.Value; return(new CSTranslationInstruction(inst.Translator.CodeGen(Context), inst.ReturnType, inst.Yields)); }); return(csClass); }
public string TranslateIff(IffFile file) { Context.Filename = CSTranslationContext.FormatName(file.Filename.Replace(".iff", "")); Context.ModuleName = Context.Filename + "Module"; Context.NamespaceName = "FSO.Scripts." + Context.Filename; Context.CurrentFile = file; var bhavs = file.List <BHAV>() ?? new List <BHAV>(); foreach (var bhav in bhavs) { Context.CurrentBHAV = bhav; var sbhav = new StructuredBHAV(bhav); sbhav.Analyse(Context); Context.BHAVInfo[bhav.ChunkID] = sbhav; } foreach (var bhav in Context.BHAVInfo.Values) { PropagateYieldFromCalls(bhav); } foreach (var bhav in Context.BHAVInfo.Values) { foreach (var inst in bhav.Instructions.Values) { (inst.Translator as CSSubroutinePrimitive)?.InitInfo(Context); } } foreach (var bhav in Context.BHAVInfo.Values) { bhav.BuildStructure(); } foreach (var bhav in Context.BHAVInfo.Values) { Context.AllClasses.Add(TranslateBHAV(bhav)); } return(BuildCSFile()); }
public CSTranslator() { Context = new CSTranslationContext(); }