示例#1
0
        public CodeMemberMethod Generate()
        {
            this.autos = new Dictionary<string, LocalSymbol>();
            this.xlat = new ExpTranslator(gen);
            this.stmtXlat = new StatementTranslator(gen, autos);

            return Generate(CreateFunctionParameters(args)); // () => bodyGenerator(f.body));
        }
        string Xlat(string pyExp)
        {
            var rdr = new StringReader(pyExp);
            var lex = new Lexer("foo.py", rdr);
            var par = new Parser("foo.py", lex);
            var exp = par.test();

            Debug.Print("{0}", exp);
            var sym    = new SymbolGenerator();
            var types  = new TypeReferenceTranslator(new Dictionary <Node, DataType>());
            var xlt    = new ExpTranslator(types, new CodeGenerator(new CodeCompileUnit(), "", "test"), sym);
            var csExp  = exp.Accept(xlt);
            var pvd    = new CSharpCodeProvider();
            var writer = new StringWriter();

            pvd.GenerateCodeFromExpression(csExp, writer,
                                           new CodeGeneratorOptions
            {
            });
            return(writer.ToString());
        }
示例#3
0
 private void ClassTranslator_GenerateField(Identifier id, ExpTranslator xlat, AssignExp ass)
 {
     IEnumerable<Exp> slotNames = null;
     var srcList = ass.Src as PyList;
     if (srcList != null)
     {
         slotNames= srcList.elts;
     }
     var srcTuple = ass.Src as PyTuple;
     if (srcTuple != null)
     {
         slotNames = srcTuple.values;
     }
     if (id.Name == "__slots__")
     {
         foreach (var slotName in slotNames.OfType<Str>())
         {
             GenerateField(slotName.s, null);
         }
     }
     else
     {
         GenerateField(id.Name, ass.Src.Accept(xlat));
     }
 }
示例#4
0
 public StatementTranslator(CodeGenerator gen, Dictionary<string, LocalSymbol> autos)
 {
     this.gen = gen;
     this.autos = autos;
     this.xlat = new ExpTranslator(gen);
 }
示例#5
0
 string Xlat(string pyExp)
 {
     var rdr = new StringReader(pyExp);
     var lex = new Syntax.Lexer("foo.py", rdr);
     var par = new Syntax.Parser("foo.py", lex);
     var exp = par.test();
     Debug.Print("{0}", exp);
     var xlt = new ExpTranslator(new CodeGenerator(new CodeCompileUnit(), "", "test"));
     var csExp = exp.Accept(xlt);
     var pvd = new CSharpCodeProvider();
     var writer = new StringWriter();
     pvd.GenerateCodeFromExpression(csExp, writer,
         new CodeGeneratorOptions
         {
         });
     return writer.ToString();
 }