/// <summary> /// Loop over all branches, trying to locate one that is equal to the given opcode /// If the branch is a branch itself, perform the locate recursively. /// </summary> /// <param name="opcode"></param> /// <returns></returns> internal override Opcode Locate(Opcode opcode) { Fx.Assert(!opcode.TestFlag(OpcodeFlags.Branch), ""); for (int i = 0, count = this.branches.Count; i < count; ++i) { Opcode branch = this.branches[i]; if (branch.TestFlag(OpcodeFlags.Branch)) { // The branch is itself a branch. Since branch opcodes serve as branches in the exection // path for a query, but don't comprise one of the opcodes used to actually perform it, we // recursively try to locate an equivalent opcode inside the branch Opcode subBranch = branch.Locate(opcode); if (null != subBranch) { return(subBranch); } } else if (branch.Equals(opcode)) { return(branch); } } return(null); }
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 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 override Opcode Locate(Opcode opcode) { int num = 0; int count = this.branches.Count; while (num < count) { Opcode opcode2 = this.branches[num]; if (opcode2.TestFlag(OpcodeFlags.Branch)) { Opcode opcode3 = opcode2.Locate(opcode); if (opcode3 != null) { return(opcode3); } } else if (opcode2.Equals(opcode)) { return(opcode2); } num++; } return(null); }