Beispiel #1
0
 public MethodGenerator(FunctionDef f, string fnName, List<Parameter> args, bool isStatic, CodeGenerator gen)
 {
     this.f = f;
     this.fnName = fnName;
     this.args = args;
     this.isStatic = isStatic;
     this.gen = gen;
 }
Beispiel #2
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 { });
 }
Beispiel #3
0
 public StatementTranslator(CodeGenerator gen, Dictionary<string, LocalSymbol> autos)
 {
     this.gen = gen;
     this.autos = autos;
     this.xlat = new ExpTranslator(gen);
 }
Beispiel #4
0
 public ModuleTranslator(CodeGenerator gen)
     : base(gen, new Dictionary<string, LocalSymbol>())
 {
     this.gen = gen;
 }
Beispiel #5
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();
        }
Beispiel #6
0
 public LambdaBodyGenerator(FunctionDef f, List<Parameter> args, bool isStatic, CodeGenerator gen)
     : base(f, null, args, isStatic, gen)
 {
 }
 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.stmt();
     var unt = new CodeCompileUnit();
     var gen = new CodeGenerator(unt, "test", "testModule");
     var xlt = new StatementTranslator(gen, new Dictionary<string, LocalSymbol>());
     stm.Accept(xlt);
     var pvd = new CSharpCodeProvider();
     var writer = new StringWriter();
     foreach (CodeNamespace ns in unt.Namespaces)
     {
         foreach (CodeNamespaceImport imp in ns.Imports)
         {
             writer.WriteLine("using {0};", SanitizeNamespace(imp.Namespace, gen));
         }
         foreach (CodeTypeDeclaration type in ns.Types)
         {
             pvd.GenerateCodeFromType(
                 type,
                 writer,
             new CodeGeneratorOptions
             {
             });
         }
     }
     return writer.ToString();
 }
 private string XlatMember(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.stmt();
     var unt = new CodeCompileUnit();
     var gen = new CodeGenerator(unt, "test", "testModule");
     var xlt = new StatementTranslator(gen, new Dictionary<string, LocalSymbol>());
     stm.Accept(xlt);
     var pvd = new CSharpCodeProvider();
     var writer = new StringWriter();
     foreach (CodeNamespace ns in unt.Namespaces)
     {
         foreach (var member in ns.Types[0].Members)
         {
             pvd.GenerateCodeFromMember(
                 member, writer,
                 new CodeGeneratorOptions
                 {
                 });
             writer.WriteLine();
         }
     }
     return writer.ToString();
 }
 /// <summary>
 /// Ensures no component of the namespace is a C# keyword.
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 private string SanitizeNamespace(string nmspace, CodeGenerator gen)
 {
     return string.Join(".",
         nmspace.Split('.')
         .Select(n => gen.EscapeKeywordName(n)));
 }
 private string XlatStmts(string pyStmt)
 {
     var rdr = new StringReader(pyStmt);
     var lex = new Syntax.Lexer("foo.py", rdr);
     var par = new Syntax.Parser("foo.py", lex);
     var stm = par.stmt();
     var gen = new CodeGenerator(new CodeCompileUnit(), "", "module");
     gen.CurrentMethod = new CodeMemberMethod();
     var xlt = new StatementTranslator(gen, new Dictionary<string, LocalSymbol>());
     stm.Accept(xlt);
     var pvd = new CSharpCodeProvider();
     var writer = new StringWriter();
     foreach (CodeStatement csStmt in gen.Scope)
     {
         pvd.GenerateCodeFromStatement(
             csStmt,
             writer,
             new CodeGeneratorOptions
             {
             });
     }
     return writer.ToString();
 }
Beispiel #11
0
 public ConstructorGenerator(FunctionDef f, List<Syntax.Parameter> args, CodeGenerator gen)
     : base(f, "", args, false, gen)
 {
 }