Example #1
0
        public static Set <Local> Get(Expression e)
        {
            var n = new FindLocals();

            n.Visit(e);
            return(n.locals);
        }
        private Expression ExtractOldExpression(MethodCall call)
        {
            var cand = call.Operands[0];

            if (this.currentSL != null)
            {
                var locs = FindLocals.Get(cand);
                if (locs.Count > 0)
                {
                    // find the instructions that set these locals
                    var assignments = new List <Statement>();
                    for (int i = this.currentSLindex - 1; i >= 0; i--)
                    {
                        var a = this.currentSL[i] as AssignmentStatement;
                        if (a == null)
                        {
                            continue;
                        }

                        var loc = a.Target as Local;
                        if (loc == null)
                        {
                            continue;
                        }

                        if (locs.Contains(loc))
                        {
                            assignments.Add(a);
                            this.currentSL[i] = null;
                            locs.Remove(loc);
                        }

                        if (locs.Count == 0)
                        {
                            break;
                        }
                    }
                    assignments.Reverse();

                    var be = new StatementList();
                    assignments.ForEach(astmt => be.Add(astmt));

                    be.Add(new ExpressionStatement(cand));
                    var sc = cand.SourceContext;

                    cand = new BlockExpression(new Block(be));
                    cand.SourceContext = sc;

                    if (locs.Count > 0)
                    {
                        // warn that we couldn't extract the local
                    }
                }
            }

            return(cand);
        }
Example #3
0
 public static Set<Local> Get(Expression e)
 {
     var n = new FindLocals();
     n.Visit(e);
     return n.locals;
 }