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;
 }
Example #2
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);
        }
Example #3
0
 internal InverseQueryMatcher(bool match)
     : base()
 {
     this.elim       = new SubExprEliminator();
     this.lastLookup = new Dictionary <object, Opcode>();
     this.match      = match;
 }
Example #4
0
 internal void Renumber(SubExprEliminator elim)
 {
     this.var = elim.NewVarID();
     for (int i = 0; i < this.children.Count; ++i)
     {
         this.children[i].Renumber(elim);
     }
 }
Example #5
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));
                }
            }
        }
        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);
                }
            }
        }
Example #7
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;
                    }
                }
            }
        }
Example #8
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;
             }
         }
     }
 }
Example #9
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));
        }
 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);
 }
Example #11
0
 internal void DecRef(SubExprEliminator elim)
 {
     this.refCount--;
     CleanUp(elim);
 }
 internal void Renumber(SubExprEliminator elim)
 {
     this.var = elim.NewVarID();
     for (int i = 0; i < this.children.Count; i++)
     {
         this.children[i].Renumber(elim);
     }
 }
 internal void DecRef(SubExprEliminator elim)
 {
     this.refCount--;
     this.CleanUp(elim);
 }
 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;
             }
         }
     }
 }
        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;
                    }
                }
            }
        }