Exemplo n.º 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;
 }
Exemplo n.º 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 { });
 }
Exemplo n.º 3
0
 public StatementTranslator(CodeGenerator gen, Dictionary<string, LocalSymbol> autos)
 {
     this.gen = gen;
     this.autos = autos;
     this.xlat = new ExpTranslator(gen);
 }
Exemplo n.º 4
0
 public ModuleTranslator(CodeGenerator gen)
     : base(gen, new Dictionary<string, LocalSymbol>())
 {
     this.gen = gen;
 }
Exemplo n.º 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();
        }
Exemplo n.º 6
0
 public LambdaBodyGenerator(FunctionDef f, List<Parameter> args, bool isStatic, CodeGenerator gen)
     : base(f, null, args, isStatic, gen)
 {
 }
Exemplo n.º 7
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.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();
 }
Exemplo n.º 8
0
 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();
 }
Exemplo n.º 9
0
 /// <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)));
 }
Exemplo n.º 10
0
 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();
 }
Exemplo n.º 11
0
 public ConstructorGenerator(FunctionDef f, List<Syntax.Parameter> args, CodeGenerator gen)
     : base(f, "", args, false, gen)
 {
 }