Пример #1
0
        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 void CleanUp(SubExprEliminator elim)
        {
            if (this.refCount == 0)
            {
                if (this.children.Count == 0)
                {
                    if (this.parent == null)
                    {
                        elim.Exprs.Remove(this);
                    }
                    else
                    {
                        this.parent.RemoveChild(this);
                        this.parent.CleanUp(elim);
                    }
                }
                else if (this.children.Count == 1)
                {
                    SubExpr child = this.children[0];

                    Opcode op = child.FirstOp;
                    op.DetachFromParent();
                    Opcode op2 = this.ops;
                    while (op2.Next != null)
                    {
                        op2 = op2.Next;
                    }
                    op2.Attach(op);
                    child.ops = this.ops;

                    if (this.parent == null)
                    {
                        elim.Exprs.Remove(this);
                        elim.Exprs.Add(child);
                        child.parent = null;
                    }
                    else
                    {
                        this.parent.RemoveChild(this);
                        this.parent.AddChild(child);
                        child.parent = this.parent;
                    }
                }
            }
        }
Пример #3
0
 internal void CleanUp(SubExprEliminator elim)
 {
     if (this.refCount == 0)
     {
         if (this.children.Count == 0)
         {
             if (this.parent == null)
             {
                 elim.Exprs.Remove(this);
             }
             else
             {
                 this.parent.RemoveChild(this);
                 this.parent.CleanUp(elim);
             }
         }
         else if (this.children.Count == 1)
         {
             SubExpr item    = this.children[0];
             Opcode  firstOp = item.FirstOp;
             firstOp.DetachFromParent();
             Opcode ops = this.ops;
             while (ops.Next != null)
             {
                 ops = ops.Next;
             }
             ops.Attach(firstOp);
             item.ops = this.ops;
             if (this.parent == null)
             {
                 elim.Exprs.Remove(this);
                 elim.Exprs.Add(item);
                 item.parent = null;
             }
             else
             {
                 this.parent.RemoveChild(this);
                 this.parent.AddChild(item);
                 item.parent = this.parent;
             }
         }
     }
 }
Пример #4
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);
        }
 internal void CleanUp(SubExprEliminator elim)
 {
     if (this.refCount == 0)
     {
         if (this.children.Count == 0)
         {
             if (this.parent == null)
             {
                 elim.Exprs.Remove(this);
             }
             else
             {
                 this.parent.RemoveChild(this);
                 this.parent.CleanUp(elim);
             }
         }
         else if (this.children.Count == 1)
         {
             SubExpr item = this.children[0];
             Opcode firstOp = item.FirstOp;
             firstOp.DetachFromParent();
             Opcode ops = this.ops;
             while (ops.Next != null)
             {
                 ops = ops.Next;
             }
             ops.Attach(firstOp);
             item.ops = this.ops;
             if (this.parent == null)
             {
                 elim.Exprs.Remove(this);
                 elim.Exprs.Add(item);
                 item.parent = null;
             }
             else
             {
                 this.parent.RemoveChild(this);
                 this.parent.AddChild(item);
                 item.parent = this.parent;
             }
         }
     }
 }