Esempio n. 1
0
        private string XlatModule(string pyModule, string filename = "module.py")
        {
            var rdr = new StringReader(pyModule);
            var lex = new Lexer(filename, rdr);
            var par = new Parser(filename, lex);
            var stm = par.Parse().ToList();
            var unt = new CodeCompileUnit();
            var gen = new CodeGenerator(unt, "test", Path.GetFileNameWithoutExtension(filename));
            var opt = new Dictionary <string, object> {
                { "quiet", true }
            };
            var ana = new AnalyzerImpl(fs, logger, opt, DateTime.Now);
            var mod = new Module(
                "module",
                new SuiteStatement(stm, filename, 0, 0),
                filename, 0, 0);

            ana.LoadModule(mod);
            var types = new TypeReferenceTranslator(ana.BuildTypeDictionary());
            var xlt   = new ModuleTranslator(types, gen);

            xlt.Translate(stm);

            var pvd    = new CSharpCodeProvider();
            var writer = new StringWriter();

            pvd.GenerateCodeFromCompileUnit(unt, writer, new CodeGeneratorOptions {
            });
            return(writer.ToString());
        }
Esempio n. 2
0
        public void TranslateModuleStatements(IEnumerable <Statement> stm, State moduleScope, TextWriter output)
        {
            var unt = new CodeCompileUnit();
            var gen = new CodeGenerator(unt, nmspace, Path.GetFileNameWithoutExtension(moduleName));
            var xlt = new ModuleTranslator(moduleScope, gen);

            xlt.Translate(stm);
            var pvd = new CSharpCodeProvider();

            pvd.GenerateCodeFromCompileUnit(unt, output, new CodeGeneratorOptions {
            });
        }
Esempio n. 3
0
 private void UpdateModules()
 {
     LOG.Debug("UpdateModules()");
     try
     {
         Program.AllModules = WGAPI.GetAllModules();
         foreach (KeyValuePair <string, ModuleData> Mod in Program.AllModules)
         {
             ModuleTranslator.Transfer(Mod.Value);
         }
         BinarySerialize.WriteToBinaryFile(Commons.GetModulesFileName(), Program.AllModules);
     }
     catch (Exception e) { LOG.Error("Error during Module import: ", e); }
 }
Esempio n. 4
0
        public void Translate(string filename, TextReader input, TextWriter output)
        {
            Debug.Print("Translating module {0} in namespace {1}", moduleName, nmspace);
            var lex = new Lexer(filename, input);
            var par = new Parser(filename, lex);
            var stm = par.Parse();
            var unt = new CodeCompileUnit();
            var gen = new CodeGenerator(unt, nmspace, Path.GetFileNameWithoutExtension(moduleName));
            var xlt = new ModuleTranslator(gen);

            xlt.Translate(stm);
            var pvd = new CSharpCodeProvider();

            pvd.GenerateCodeFromCompileUnit(unt, output, new CodeGeneratorOptions {
            });
        }
Esempio n. 5
0
 public void TranslateModuleStatements(
     IEnumerable <Statement> stm,
     TypeReferenceTranslator types,
     TextWriter output)
 {
     try
     {
         var unt = new CodeCompileUnit();
         var gen = new CodeGenerator(unt, nmspace, Path.GetFileNameWithoutExtension(moduleName));
         var xlt = new ModuleTranslator(types, gen);
         xlt.Translate(stm);
         var pvd = new CSharpCodeProvider();
         pvd.GenerateCodeFromCompileUnit(unt, output, new CodeGeneratorOptions {
         });
     }
     catch (NodeException nex)
     {
         logger.Error($"{nex.Node.Filename}({nex.Node.Start}): {nex.Message}");
     }
 }
Esempio n. 6
0
        private string XlatModule(string pyModule)
        {
            var rdr = new StringReader(pyModule);
            var lex = new Syntax.Lexer("foo.py", rdr);
            var par = new Syntax.Parser("foo.py", lex);
            var stm = par.Parse();;
            var unt = new CodeCompileUnit();
            var gen = new CodeGenerator(unt, "test", "testModule");
            var xlt = new ModuleTranslator(gen);

            xlt.Translate(stm);

            var pvd    = new CSharpCodeProvider();
            var writer = new StringWriter();

            pvd.GenerateCodeFromCompileUnit(
                unt,
                writer,
                new CodeGeneratorOptions
            {
            });
            return(writer.ToString());
        }
        private string XlatModule(string pyModule)
        {
            var rdr   = new StringReader(pyModule);
            var lex   = new Lexer("foo.py", rdr);
            var par   = new Parser("foo.py", lex);
            var stm   = par.Parse();
            var unt   = new CodeCompileUnit();
            var gen   = new CodeGenerator(unt, "test", "testModule");
            var types = new TypeReferenceTranslator(new Dictionary <Node, DataType>());
            var xlt   = new ModuleTranslator(types, gen);

            xlt.Translate(stm);

            var pvd    = new CSharpCodeProvider();
            var writer = new StringWriter();

            pvd.GenerateCodeFromCompileUnit(
                unt,
                writer,
                new CodeGeneratorOptions
            {
            });
            return(writer.ToString());
        }