Beispiel #1
0
        public static void Generate(CodeMemberMethod method, HashSet <string> globals)
        {
            var gen = new LocalVariableGenerator(method.Parameters, method.Statements, globals);

            gen.Analyze(new List <CodeStatement>(), method.Statements);
            gen.Generate();
        }
Beispiel #2
0
        public void VisitDecorated(Decorated d)
        {
            var decorators = d.Decorations.ToList();

            if (this.properties.TryGetValue(d, out var propdef))
            {
                if (propdef.IsTranslated)
                {
                    return;
                }
                decorators.Remove(propdef.GetterDecoration);
                decorators.Remove(propdef.SetterDecoration);
                this.customAttrs = decorators.Select(dd => VisitDecorator(dd));
                var prop = gen.PropertyDef(
                    propdef.Name,
                    () => GeneratePropertyGetter(propdef.Getter),
                    () => GeneratePropertySetter(propdef.Setter));
                LocalVariableGenerator.Generate(null, prop.GetStatements, globals);
                LocalVariableGenerator.Generate(
                    new List <CodeParameterDeclarationExpression> {
                    new CodeParameterDeclarationExpression(prop.PropertyType, "value"),
                },
                    prop.SetStatements,
                    globals);
                propdef.IsTranslated = true;
            }
            else
            {
                this.customAttrs = d.Decorations.Select(dd => VisitDecorator(dd));
                d.Statement.Accept(this);
            }
        }
Beispiel #3
0
        public static void Generate(CodeMemberMethod method)
        {
            var gen = new LocalVariableGenerator(method);

            gen.Analyze(new List <CodeStatement>(), method.Statements);
            gen.Generate();
        }
Beispiel #4
0
        public static void Generate(List <CodeParameterDeclarationExpression> parameters, List <CodeStatement> statements, HashSet <string> globals)
        {
            parameters = parameters ?? new List <CodeParameterDeclarationExpression>();
            var gen = new LocalVariableGenerator(parameters, statements, globals);

            gen.Analyze(new List <CodeStatement>(), statements);
            gen.Generate();
        }
Beispiel #5
0
        protected override CodeMemberMethod Generate(CodeTypeReference retType, CodeParameterDeclarationExpression[] parms)
        {
            var method = gen.LambdaMethod(parms, () => Xlat(f.body));

            GenerateTupleParameterUnpackers(method);
            LocalVariableGenerator.Generate(method, globals);
            return(method);
        }
Beispiel #6
0
        protected override CodeMemberMethod Generate(CodeTypeReference ignore, CodeParameterDeclarationExpression[] parms)
        {
            var cons = gen.Constructor(parms, () => XlatConstructor(f.body));

            GenerateTupleParameterUnpackers(cons);
            LocalVariableGenerator.Generate(cons, globals);
            return(cons);
        }
Beispiel #7
0
        protected virtual CodeMemberMethod Generate(CodeParameterDeclarationExpression[] parms)
        {
            CodeMemberMethod method;

            if (isStatic)
            {
                method = gen.StaticMethod(fnName, parms, () => Xlat(f.body));
            }
            else
            {
                method = gen.Method(fnName, parms, () => Xlat(f.body));
            }
            GenerateTupleParameterUnpackers(method);
            LocalVariableGenerator.Generate(method);
            return(method);
        }
Beispiel #8
0
        protected virtual CodeMemberMethod Generate(CodeTypeReference retType, CodeParameterDeclarationExpression[] parms)
        {
            CodeMemberMethod method;

            if (isStatic)
            {
                method = gen.StaticMethod(fnName, retType, parms, () => Xlat(f.body));
            }
            else
            {
                method = gen.Method(fnName, retType, parms, () => Xlat(f.body));
            }
            method.IsAsync = isAsync;
            GenerateTupleParameterUnpackers(method);
            LocalVariableGenerator.Generate(method, globals);
            return(method);
        }
Beispiel #9
0
        /// <summary>
        /// Processes the decorators of <paramref name="stmt"/>.
        /// </summary>
        /// <param name="stmt"></param>
        /// <returns>If true, the body of the statement has been
        /// translated, so don't do it again.</returns>
        public bool VisitDecorators(Statement stmt)
        {
            if (stmt.decorators == null)
            {
                return(false);
            }
            var decorators = stmt.decorators;

            if (this.properties.TryGetValue(stmt, out var propdef))
            {
                if (propdef.IsTranslated)
                {
                    return(true);
                }
                decorators.Remove(propdef.GetterDecoration);
                decorators.Remove(propdef.SetterDecoration);
                this.customAttrs = decorators.Select(dd => VisitDecorator(dd));
                var prop = gen.PropertyDef(
                    propdef.Name,
                    () => GeneratePropertyGetter(propdef.Getter),
                    () => GeneratePropertySetter(propdef.Setter));
                LocalVariableGenerator.Generate(null, prop.GetStatements, globals);
                LocalVariableGenerator.Generate(
                    new List <CodeParameterDeclarationExpression> {
                    new CodeParameterDeclarationExpression(prop.PropertyType, "value"),
                },
                    prop.SetStatements,
                    globals);
                propdef.IsTranslated = true;
                return(true);
            }
            else
            {
                this.customAttrs = stmt.decorators.Select(dd => VisitDecorator(dd));
                return(false);
            }
        }