private void ClassTranslator_GenerateField(Identifier id, ExpTranslator xlat, AssignExp ass) { IEnumerable <Exp> slotNames = null; if (ass.Src is PyList srcList) { slotNames = srcList.elts; } else if (ass.Src is PyTuple srcTuple) { slotNames = srcTuple.values; } if (id.Name == "__slots__") { if (slotNames == null) { // dynamically generated slots are hard. gen.Comment(ass.ToString()); } else { foreach (var slotName in slotNames.OfType <Str>()) { GenerateField(slotName.s, null); } } } else { GenerateField(id.Name, ass.Src.Accept(xlat)); } }
public StatementTranslator(CodeGenerator gen, SymbolGenerator gensym) { this.gen = gen; this.gensym = gensym; this.xlat = new ExpTranslator(gen, gensym); this.properties = new Dictionary <Decorated, PropertyDefinition>(); }
public CodeMemberMethod Generate() { this.gensym = new SymbolGenerator(); this.xlat = new ExpTranslator(gen, gensym); this.stmtXlat = new StatementTranslator(gen, gensym); return(Generate(CreateFunctionParameters(args))); // () => bodyGenerator(f.body)); }
public StatementTranslator(TypeReferenceTranslator types, CodeGenerator gen, SymbolGenerator gensym, HashSet <string> globals) { this.types = types; this.gen = gen; this.gensym = gensym; this.xlat = new ExpTranslator(types, gen, gensym); this.properties = new Dictionary <Statement, PropertyDefinition>(); this.globals = globals; }
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; this.gensym = new SymbolGenerator(); this.xlat = new ExpTranslator(gen, gensym); this.stmtXlat = new StatementTranslator(gen, gensym); }
private void ClassTranslator_GenerateField(Identifier id, ExpTranslator xlat, AssignExp ass) { if (id.Name == "__slots__") { // We should already have analyzed the slots in // the type inference phase, so we ignore __slots__. return; } else { var(fieldType, nmspcs) = types.TranslateTypeOf(id); gen.EnsureImports(nmspcs); GenerateField(id.Name, fieldType, ass.Src.Accept(xlat)); } }
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 sym = new SymbolGenerator(); var xlt = new ExpTranslator(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()); }
public MethodGenerator( FunctionDef f, string fnName, List <Parameter> args, bool isStatic, bool isAsync, TypeReferenceTranslator types, CodeGenerator gen) { this.f = f; this.fnName = fnName; this.args = args; this.isStatic = isStatic; this.isAsync = isAsync; this.gen = gen; this.gensym = new SymbolGenerator(); this.types = new TypeReferenceTranslator(new Dictionary <Node, DataType>()); this.xlat = new ExpTranslator(this.types, gen, gensym); this.globals = new HashSet <string>(); this.stmtXlat = new StatementTranslator(types, gen, gensym, globals); }
public IntrinsicTranslator(ExpTranslator expTranslator) { this.expTranslator = expTranslator; this.m = expTranslator.m; this.translators = new Dictionary <string, Func <Application, CodeExpression[], CodeExpression> > { { "isinstance", Translate_isinstance }, { "int", Translate_int }, { "list", Translate_list }, { "set", Translate_set }, { "dict", Translate_dict }, { "len", Translate_len }, { "sum", Translate_sum }, { "filter", Translate_filter }, { "complex", Translate_complex }, { "float", Translate_float }, { "sorted", Translate_sorted }, { "str", Translate_str }, { "enumerate", Translate_enumerate }, }; }
private void ClassTranslator_GenerateField(Identifier id, ExpTranslator xlat, AssignExp ass) { IEnumerable <Exp> slotNames = null; if (ass.Src is PyList srcList) { slotNames = srcList.elts; } else if (ass.Src is PyTuple srcTuple) { slotNames = srcTuple.values; } if (id.Name == "__slots__") { if (slotNames == null) { // dynamically generated slots are hard. gen.Comment(ass.ToString()); } else { foreach (var slotName in slotNames.OfType <Str>()) { //$TODO: test type inference for slots. var slotType = new CodeTypeReference(typeof(object)); GenerateField(slotName.s, slotType, null); } } } else { var(fieldType, nmspcs) = types.TranslateTypeOf(id); gen.EnsureImports(nmspcs); GenerateField(id.Name, fieldType, ass.Src.Accept(xlat)); } }
public IntrinsicTranslator(ExpTranslator expTranslator) { this.expTranslator = expTranslator; this.m = expTranslator.m; }
public StatementTranslator(CodeGenerator gen, SymbolGenerator gensym) { this.gen = gen; this.gensym = gensym; this.xlat = new ExpTranslator(gen, gensym); }