Exemplo n.º 1
0
        public void VisitClass(ClassDef c)
        {
            if (VisitDecorators(c))
            {
                return;
            }
            var baseClasses = c.args.Select(a => GenerateBaseClassName(a.defval !)).ToList();
            var comments    = ConvertFirstStringToComments(c.body.stmts);
            var gensym      = new SymbolGenerator();
            var stmtXlt     = new StatementTranslator(c, types, gen, gensym, new HashSet <string>());

            stmtXlt.properties = FindProperties(c.body.stmts);
            var csClass = gen.Class(
                c.name.Name,
                baseClasses,
                () => GenerateFields(c),
                () => c.body.Accept(stmtXlt));

            csClass.Comments.AddRange(comments);
            if (customAttrs != null)
            {
                csClass.CustomAttributes.AddRange(customAttrs);
                customAttrs = null;
            }
        }
Exemplo n.º 2
0
        public void Xlat(SuiteStatement suite)
        {
            var comments = StatementTranslator.ConvertFirstStringToComments(suite.stmts);

            stmtXlat.Xlat(suite);
            gen.CurrentMemberComments.AddRange(comments);
        }
Exemplo n.º 3
0
        private void XlatConstructor(SuiteStatement stmt)
        {
            if (stmt == null)
            {
                return;
            }

            var comments = StatementTranslator.ConvertFirstStringToComments(stmt.stmts);

            stmt.Accept(this.stmtXlat);
            if (gen.Scope.Count == 0)
            {
                return;
            }
            gen.Scope[0].ToString();
            if (!(gen.Scope[0] is CodeExpressionStatement expStm))
            {
                return;
            }
            if (!(expStm.Expression is CodeApplicationExpression appl))
            {
                return;
            }
            if (!(appl.Method is CodeFieldReferenceExpression method) || method.FieldName != "__init__")
            {
                return;
            }
            var ctor = (CodeConstructor)gen.CurrentMember !;

            ctor.Comments.AddRange(comments);
            ctor.BaseConstructorArgs.AddRange(appl.Arguments.Skip(1));
            gen.Scope.RemoveAt(0);
        }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 public MethodGenerator(
     ClassDef?classDef,
     FunctionDef f,
     string?fnName,
     List <Parameter> args,
     bool isStatic,
     bool isAsync,
     TypeReferenceTranslator types,
     CodeGenerator gen)
 {
     this.classDef = classDef;
     this.f        = f;
     this.fnName   = fnName;
     this.args     = args;
     this.isStatic = isStatic;
     this.isAsync  = isAsync;
     this.gen      = gen;
     this.gensym   = new SymbolGenerator();
     this.types    = types;
     this.xlat     = new ExpTranslator(classDef, this.types, gen, gensym);
     this.globals  = new HashSet <string>();
     this.stmtXlat = new StatementTranslator(classDef, types, gen, gensym, globals);
 }