示例#1
0
        public static IEnumerable <Expr> Get(ICode ast, Expr.Special specials)
        {
            var v = new VisitorFindSpecials(specials);

            v.Visit(ast);
            return(v.results);
        }
        protected override ICode VisitAssignment(StmtAssignment s)
        {
            var aInfo = this.GetAInfo(s.Target);

            aInfo.assignment = s;
            if (s.Target.ExprType != Expr.NodeType.VarLocal || s.Target.Type.IsByReference ||
                VisitorFindSpecials.Any(s.Expr, Expr.Special.PossibleSideEffects))
            {
                aInfo.mustKeep = true;
            }
            this.Visit(s.Target);
            this.Visit(s.Expr);
            return(s);
        }
        // TODO: Restrict movement across try/catch/finally borders

        public static ICode V(ICode ast)
        {
            var v               = new VisitorSsaCopyPropagation();
            var ast2            = v.Visit(ast);
            var alreadyReplaced = new Dictionary <Expr, Expr>();

            foreach (var a in v.assignments.Values)
            {
                if (a.mustKeep)
                {
                    continue;
                }
                if (a.assignment == null)
                {
                    continue;
                }
                if (a.count == 1)
                {
                    if (!VisitorFindSpecials.Any(a.assignment, Expr.Special.PossibleSideEffects))
                    {
                        ast2 = VisitorReplace.V(ast2, a.assignment, null);
                    }
                }
                else if (a.count == 2 /*||
                                       * (IsSimple(alreadyReplaced.ValueOrDefault(a.assignment.Expr, a.assignment.Expr)) && !a.assignment.Expr.Type.IsNonPrimitiveValueType())*/)
                {
                    var updater = new Updater(a.assignment.Target);
                    ast2 = updater.Visit(ast2);
                    foreach (var replaced in updater.Replaced)
                    {
                        alreadyReplaced[replaced.Item1] = replaced.Item2;
                    }
                }
            }
            return(ast2);
        }
 public static IEnumerable<Expr> Get(ICode ast, Expr.Special specials) {
     var v = new VisitorFindSpecials(specials);
     v.Visit(ast);
     return v.results;
 }