internal Opcode Add(object item, Opcode ops)
 {
     List<SubExpr> list = new List<SubExpr>();
     this.removalMapping.Add(item, list);
     while (ops.Next != null)
     {
         ops = ops.Next;
     }
     Opcode opcode = ops;
     while (ops != null)
     {
         if (IsExprStarter(ops))
         {
             SubExprOpcode opcode4;
             Opcode op = ops;
             Opcode prev = ops.Prev;
             ops.DetachFromParent();
             ops = ops.Next;
             while (ops.ID == OpcodeID.Select)
             {
                 ops = ops.Next;
             }
             ops.DetachFromParent();
             SubExpr expr = null;
             for (int i = 0; i < this.exprList.Count; i++)
             {
                 if (this.exprList[i].FirstOp.Equals(op))
                 {
                     expr = this.exprList[i];
                     break;
                 }
             }
             if (expr == null)
             {
                 expr = new SubExpr(null, op, this.NewVarID());
                 this.exprList.Add(expr);
                 opcode4 = new SubExprOpcode(expr);
             }
             else
             {
                 opcode4 = expr.Add(op, this);
             }
             opcode4.Expr.IncRef();
             list.Add(opcode4.Expr);
             opcode4.Attach(ops);
             ops = opcode4;
             if (prev != null)
             {
                 prev.Attach(ops);
             }
         }
         opcode = ops;
         ops = ops.Prev;
     }
     return opcode;
 }
Пример #2
0
        internal Opcode Add(object item, Opcode ops)
        {
            List <SubExpr> exprs = new List <SubExpr>();

            this.removalMapping.Add(item, exprs);

            while (ops.Next != null)
            {
                ops = ops.Next;
            }

            Opcode res = ops;

            while (ops != null)
            {
                if (IsExprStarter(ops))
                {
                    Opcode start = ops;
                    Opcode p     = ops.Prev;
                    ops.DetachFromParent();

                    ops = ops.Next;
                    while (ops.ID == OpcodeID.Select)
                    {
                        ops = ops.Next;
                    }
                    ops.DetachFromParent();

                    SubExpr e = null;
                    for (int i = 0; i < this.exprList.Count; ++i)
                    {
                        if (this.exprList[i].FirstOp.Equals(start))
                        {
                            e = this.exprList[i];
                            break;
                        }
                    }

                    SubExprOpcode o;
                    if (e == null)
                    {
                        e = new SubExpr(null, start, NewVarID());
                        this.exprList.Add(e);
                        o = new SubExprOpcode(e);
                    }
                    else
                    {
                        o = e.Add(start, this);
                    }

                    o.Expr.IncRef();
                    exprs.Add(o.Expr);
                    o.Attach(ops);
                    ops = o;

                    if (p != null)
                    {
                        p.Attach(ops);
                    }
                }

                res = ops;
                ops = ops.Prev;
            }

            return(res);
        }
 private SubExpr BranchAt(Opcode op, SubExprEliminator elim)
 {
     Opcode firstOp = this.FirstOp;
     if (this.parent != null)
     {
         this.parent.RemoveChild(this);
     }
     else
     {
         elim.Exprs.Remove(this);
     }
     firstOp.DetachFromParent();
     op.DetachFromParent();
     SubExpr expr = new SubExpr(this.parent, firstOp, elim.NewVarID());
     if (this.parent != null)
     {
         this.parent.AddChild(expr);
     }
     else
     {
         elim.Exprs.Add(expr);
     }
     expr.AddChild(this);
     this.parent = expr;
     this.ops = new InternalSubExprOpcode(expr);
     this.ops.Attach(op);
     return expr;
 }
        internal SubExprOpcode Add(Opcode opseq, SubExprEliminator elim)
        {
            Opcode start = this.FirstOp;
            Opcode ops = opseq;
            while (start != null && ops != null && start.Equals(ops))
            {
                start = start.Next;
                ops = ops.Next;
            }

            if (ops == null)
            {
                if (start == null)
                {
                    return new SubExprOpcode(this);
                }
                else
                {
                    SubExpr e = this.BranchAt(start, elim);
                    return new SubExprOpcode(e);
                }
            }
            else
            {
                if (start == null)
                {
                    ops.DetachFromParent();
                    for (int i = 0; i < this.children.Count; ++i)
                    {
                        if (this.children[i].FirstOp.Equals(ops))
                        {
                            return this.children[i].Add(ops, elim);
                        }
                    }

                    SubExpr e = new SubExpr(this, ops, elim.NewVarID());
                    this.AddChild(e);
                    return new SubExprOpcode(e);
                }
                else
                {
                    SubExpr e = this.BranchAt(start, elim);
                    ops.DetachFromParent();
                    SubExpr ee = new SubExpr(e, ops, elim.NewVarID());
                    e.AddChild(ee);
                    return new SubExprOpcode(ee);
                }
            }
        }
        internal Opcode Add(object item, Opcode ops)
        {
            List<SubExpr> exprs = new List<SubExpr>();
            this.removalMapping.Add(item, exprs);

            while (ops.Next != null)
            {
                ops = ops.Next;
            }

            Opcode res = ops;
            while (ops != null)
            {
                if (IsExprStarter(ops))
                {
                    Opcode start = ops;
                    Opcode p = ops.Prev;
                    ops.DetachFromParent();

                    ops = ops.Next;
                    while (ops.ID == OpcodeID.Select)
                    {
                        ops = ops.Next;
                    }
                    ops.DetachFromParent();

                    SubExpr e = null;
                    for (int i = 0; i < this.exprList.Count; ++i)
                    {
                        if (this.exprList[i].FirstOp.Equals(start))
                        {
                            e = this.exprList[i];
                            break;
                        }
                    }

                    SubExprOpcode o;
                    if (e == null)
                    {
                        e = new SubExpr(null, start, NewVarID());
                        this.exprList.Add(e);
                        o = new SubExprOpcode(e);
                    }
                    else
                    {
                        o = e.Add(start, this);
                    }

                    o.Expr.IncRef();
                    exprs.Add(o.Expr);
                    o.Attach(ops);
                    ops = o;

                    if (p != null)
                    {
                        p.Attach(ops);
                    }
                }

                res = ops;
                ops = ops.Prev;
            }

            return res;
        }