Ejemplo n.º 1
0
        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 e = new SubExpr(this.parent, firstOp, elim.NewVarID());

            if (this.parent != null)
            {
                this.parent.AddChild(e);
            }
            else
            {
                elim.Exprs.Add(e);
            }
            e.AddChild(this);
            this.parent = e;
            this.ops    = new InternalSubExprOpcode(e);
            this.ops.Attach(op);
            return(e);
        }
Ejemplo n.º 2
0
        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));
                }
            }
        }
Ejemplo n.º 3
0
        internal SubExprOpcode Add(Opcode opseq, SubExprEliminator elim)
        {
            Opcode firstOp = this.FirstOp;
            Opcode op      = opseq;

            while (((firstOp != null) && (op != null)) && firstOp.Equals(op))
            {
                firstOp = firstOp.Next;
                op      = op.Next;
            }
            if (op == null)
            {
                if (firstOp == null)
                {
                    return(new SubExprOpcode(this));
                }
                return(new SubExprOpcode(this.BranchAt(firstOp, elim)));
            }
            if (firstOp == null)
            {
                op.DetachFromParent();
                for (int i = 0; i < this.children.Count; i++)
                {
                    if (this.children[i].FirstOp.Equals(op))
                    {
                        return(this.children[i].Add(op, elim));
                    }
                }
                SubExpr expr2 = new SubExpr(this, op, elim.NewVarID());
                this.AddChild(expr2);
                return(new SubExprOpcode(expr2));
            }
            SubExpr parent = this.BranchAt(firstOp, elim);

            op.DetachFromParent();
            SubExpr expr = new SubExpr(parent, op, elim.NewVarID());

            parent.AddChild(expr);
            return(new SubExprOpcode(expr));
        }
 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;
 }