Package xbird.xquery.expr.comp

Examples of xbird.xquery.expr.comp.ComparisonOp


        int nWhereSize = whereExprs.size();
        for(int oi = 0; oi < nWhereSize; oi++) {
            final XQExpression eachExpr = whereExprs.get(oi);
            boolean innerModified = false;
            if(eachExpr instanceof ComparisonOp) {
                final ComparisonOp cmpOpr = (ComparisonOp) eachExpr;
                XQExpression replaceVarRef = null;
                inner: for(int ii = 0; ii < 2; ii++) {
                    final XQExpression left = cmpOpr.getLeftOperand();
                    final XQExpression right = cmpOpr.getRightOperand();
                    if(left instanceof VarRef) {
                        final Variable referent = ((VarRef) left).getValue();
                        if(firstBindingExpr instanceof PathExpr) {
                            final PathExpr bindingPathExpr = (PathExpr) firstBindingExpr;
                            if(firstBindingVar == referent) {
                                cmpOpr.setLeftOperand(new ContextItemExpr(bindingPathExpr.getType()));
                                bindingPathExpr.addPredicate(cmpOpr);
                                innerModified = true;
                                replaceVarRef = firstBindingVar;
                                break inner;
                            } else if((firstBindingType == Binding.FOR_CLAUSE)
                                    && (cmpOpr instanceof GeneralComp)) {
                                final PositionalVariable posVar = ((ForClause) firstBinding).getPositionVariable();
                                if(posVar == referent) {
                                    bindingPathExpr.addPredicate(right);
                                    innerModified = true;
                                    replaceVarRef = posVar;
                                    break inner;
                                }
                            }
                        }
                    } else if(left instanceof RelativePath) {
                        final RelativePath leftPathExpr = ((RelativePath) left);
                        final List<XQExpression> steps = leftPathExpr.getSteps();
                        final XQExpression firstStep = steps.get(0);
                        if(firstStep instanceof VarRef) {
                            final Variable referent = ((VarRef) firstStep).getValue();
                            if(firstBindingVar == referent) {
                                if(firstBindingExpr instanceof VarRef) {
                                    final Variable ref = ((VarRef) firstBindingExpr).getValue();
                                    final XQExpression refval = ref.getValue();
                                    if(refval instanceof PathExpr) {
                                        firstBindingExpr = refval;
                                    }
                                }
                                if(firstBindingExpr instanceof PathExpr) {
                                    final PathExpr bindingPathExpr = (PathExpr) firstBindingExpr;
                                    steps.remove(0);
                                    assert (!steps.isEmpty());
                                    bindingPathExpr.addPredicate(cmpOpr);
                                    innerModified = true;
                                    replaceVarRef = firstBindingVar;
                                    break inner;
                                }
                            } else if(ii == 1) {// delete an unnessesary where clause
                                innerModified = true;
                                break inner;
                            }
                        }
                    } else if(left instanceof DirectFunctionCall) {
                        final Function func = ((DirectFunctionCall) left).getFunction();
                        if(func instanceof Position) {
                            if(firstBindingExpr instanceof PathExpr) {
                                final PathExpr bindingPathExpr = (PathExpr) firstBindingExpr;
                                if(TypeUtil.subtypeOf(right.getType(), NumericType.getInstance())) {
                                    bindingPathExpr.addPredicate(right);
                                } else {
                                    TypePromotedExpr typePromoted = new TypePromotedExpr(right, IntegerType.INTEGER);
                                    bindingPathExpr.addPredicate(typePromoted);
                                }
                                innerModified = true;
                                break inner;
                            }
                        }
                    } else {
                        if(firstBindingExpr instanceof PathExpr) {
                            final PathExpr bindingPathExpr = (PathExpr) firstBindingExpr;
                            final VarRefDetector detector1 = new VarRefDetector(firstBindingVar, true);
                            detector1.visit(left, null);
                            if(detector1.isDetected()) {
                                final VarRefDetector detector2 = new VarRefDetector(firstBindingVar, false);
                                detector2.visit(right, null);
                                if(detector2.isJoinDisabled() || detector2.isDetected()) {
                                    break inner;
                                } else {
                                    bindingPathExpr.addPredicate(cmpOpr);
                                    innerModified = true;
                                    break inner;
                                }
                            }
                        }
                    }
                    cmpOpr.switchOperand();
                }//inner
                if(replaceVarRef != null) {
                    final PredicateReplacer replacer = new PredicateReplacer(replaceVarRef);
                    replacer.visit(cmpOpr, null);
                }
View Full Code Here


            case Is:
            case LtEquals:
            case LtLt:
            case Lt:
            case NotEquals:
                final ComparisonOp op;
                switch(jj_nt.kind) {
                    case FortranEq:
                    case FortranGe:
                    case FortranGt:
                    case FortranLe:
                    case FortranLt:
                    case FortranNe:
                        final ValueComp.Operator vcmp;
                        switch(jj_nt.kind) {
                            case FortranEq:
                                // "eq" | "ne" | "lt" | "le" | "gt" | "ge" 
                                currentToken = jj_consume_token(FortranEq);
                                vcmp = ValueComp.Operator.EQ;
                                break;
                            case FortranNe:
                                currentToken = jj_consume_token(FortranNe);
                                vcmp = ValueComp.Operator.NE;
                                break;
                            case FortranLt:
                                currentToken = jj_consume_token(FortranLt);
                                vcmp = ValueComp.Operator.LT;
                                break;
                            case FortranLe:
                                currentToken = jj_consume_token(FortranLe);
                                vcmp = ValueComp.Operator.LE;
                                break;
                            case FortranGt:
                                currentToken = jj_consume_token(FortranGt);
                                vcmp = ValueComp.Operator.GT;
                                break;
                            case FortranGe:
                                currentToken = jj_consume_token(FortranGe);
                                vcmp = ValueComp.Operator.GE;
                                break;
                            default:
                                jj_la1[92] = jj_gen;
                                jj_consume_token(-1);
                                throw new ParseException();
                        }
                        op = new ValueComp(vcmp, expr);
                        break;
                    case Equals:
                    case GtEquals:
                    case Gt:
                    case LtEquals:
                    case Lt:
                    case NotEquals:
                        final GeneralComp.Operator gcmp;
                        switch(jj_nt.kind) {
                            case Equals:
                                // "=" | "!=" | "<" | "<=" | ">" | ">="
                                currentToken = jj_consume_token(Equals);
                                gcmp = GeneralComp.Operator.EQ;
                                break;
                            case NotEquals:
                                currentToken = jj_consume_token(NotEquals);
                                gcmp = GeneralComp.Operator.NE;
                                break;
                            case Lt:
                                currentToken = jj_consume_token(Lt);
                                gcmp = GeneralComp.Operator.LT;
                                break;
                            case LtEquals:
                                currentToken = jj_consume_token(LtEquals);
                                gcmp = GeneralComp.Operator.LE;
                                break;
                            case Gt:
                                currentToken = jj_consume_token(Gt);
                                gcmp = GeneralComp.Operator.GT;
                                break;
                            case GtEquals:
                                currentToken = jj_consume_token(GtEquals);
                                gcmp = GeneralComp.Operator.GE;
                                break;
                            default:
                                jj_la1[93] = jj_gen;
                                jj_consume_token(-1);
                                throw new ParseException();
                        }
                        op = new GeneralComp(gcmp, expr);
                        break;
                    case GtGt:
                    case Is:
                    case LtLt:
                        final NodeComp.Operator ncmp;
                        switch(jj_nt.kind) {
                            case Is:
                                // "is" | "<<" | ">>"
                                currentToken = jj_consume_token(Is);
                                ncmp = NodeComp.Operator.IS;
                                break;
                            case LtLt:
                                currentToken = jj_consume_token(LtLt);
                                ncmp = NodeComp.Operator.PRECEDES;
                                break;
                            case GtGt:
                                currentToken = jj_consume_token(GtGt);
                                ncmp = NodeComp.Operator.FOLLOWS;
                                break;
                            default:
                                jj_la1[94] = jj_gen;
                                jj_consume_token(-1);
                                throw new ParseException();
                        }
                        op = new NodeComp(ncmp, expr);
                        break;
                    default:
                        jj_la1[95] = jj_gen;
                        jj_consume_token(-1);
                        throw new ParseException();
                }
                rightExpr = parseRangeExpr();
                op.setRightOperand(rightExpr);
                expr = locate(op);
                break;
            default:
                jj_la1[96] = jj_gen;
                ;
View Full Code Here

            String opr = null;
            for(XQExpression p : predicates) {
                if(p instanceof ConditionalFilter) {
                    XQExpression pred = ((ConditionalFilter) p).getPredicate();
                    if((pred instanceof GeneralComp) || (pred instanceof NodeComp)) {
                        ComparisonOp cmpOp = (ComparisonOp) pred;
                        String newOpr = cmpOp.getOperator();
                        if(opr != null && opr != newOpr) {
                            break;
                        }
                        opr = newOpr;
                        XQExpression left = cmpOp.getLeftOperand();
                        if(left instanceof VarRef) {
                            left = ((VarRef) left).getValue();
                        }
                        if(left instanceof PathVariable) {
                            left = ((PathVariable) left).getValue();
                        }
                        XQExpression right = cmpOp.getRightOperand();
                        if(right instanceof VarRef) {
                            right = ((VarRef) right).getValue();
                        }
                        if(right instanceof PathVariable) {
                            right = ((PathVariable) right).getValue();
View Full Code Here

            String opr = null;
            for(XQExpression p : predicates) {
                if(p instanceof ConditionalFilter) {
                    XQExpression pred = ((ConditionalFilter) p).getPredicate();
                    if((pred instanceof GeneralComp) || (pred instanceof NodeComp)) {
                        ComparisonOp cmpOp = (ComparisonOp) pred;
                        String newOpr = cmpOp.getOperator();
                        if(opr != null && opr != newOpr) {
                            break;
                        }
                        opr = newOpr;
                        XQExpression left = cmpOp.getLeftOperand();
                        if(left instanceof VarRef) {
                            left = ((VarRef) left).getValue();
                        }
                        if(left instanceof PathVariable) {
                            left = ((PathVariable) left).getValue();
                        }
                        XQExpression right = cmpOp.getRightOperand();
                        if(right instanceof VarRef) {
                            right = ((VarRef) right).getValue();
                        }
                        if(right instanceof PathVariable) {
                            right = ((PathVariable) right).getValue();
View Full Code Here

            case Is:
            case LtEquals:
            case LtLt:
            case Lt:
            case NotEquals:
                final ComparisonOp op;
                switch(jj_nt.kind) {
                    case FortranEq:
                    case FortranGe:
                    case FortranGt:
                    case FortranLe:
                    case FortranLt:
                    case FortranNe:
                        final ValueComp.Operator vcmp;
                        switch(jj_nt.kind) {
                            case FortranEq:
                                // "eq" | "ne" | "lt" | "le" | "gt" | "ge" 
                                currentToken = jj_consume_token(FortranEq);
                                vcmp = ValueComp.Operator.EQ;
                                break;
                            case FortranNe:
                                currentToken = jj_consume_token(FortranNe);
                                vcmp = ValueComp.Operator.NE;
                                break;
                            case FortranLt:
                                currentToken = jj_consume_token(FortranLt);
                                vcmp = ValueComp.Operator.LT;
                                break;
                            case FortranLe:
                                currentToken = jj_consume_token(FortranLe);
                                vcmp = ValueComp.Operator.LE;
                                break;
                            case FortranGt:
                                currentToken = jj_consume_token(FortranGt);
                                vcmp = ValueComp.Operator.GT;
                                break;
                            case FortranGe:
                                currentToken = jj_consume_token(FortranGe);
                                vcmp = ValueComp.Operator.GE;
                                break;
                            default:
                                jj_la1[87] = jj_gen;
                                jj_consume_token(-1);
                                throw new ParseException();
                        }
                        op = new ValueComp(vcmp, expr);
                        break;
                    case Equals:
                    case GtEquals:
                    case Gt:
                    case LtEquals:
                    case Lt:
                    case NotEquals:
                        final GeneralComp.Operator gcmp;
                        switch(jj_nt.kind) {
                            case Equals:
                                // "=" | "!=" | "<" | "<=" | ">" | ">="
                                currentToken = jj_consume_token(Equals);
                                gcmp = GeneralComp.Operator.EQ;
                                break;
                            case NotEquals:
                                currentToken = jj_consume_token(NotEquals);
                                gcmp = GeneralComp.Operator.NE;
                                break;
                            case Lt:
                                currentToken = jj_consume_token(Lt);
                                gcmp = GeneralComp.Operator.LT;
                                break;
                            case LtEquals:
                                currentToken = jj_consume_token(LtEquals);
                                gcmp = GeneralComp.Operator.LE;
                                break;
                            case Gt:
                                currentToken = jj_consume_token(Gt);
                                gcmp = GeneralComp.Operator.GT;
                                break;
                            case GtEquals:
                                currentToken = jj_consume_token(GtEquals);
                                gcmp = GeneralComp.Operator.GE;
                                break;
                            default:
                                jj_la1[88] = jj_gen;
                                jj_consume_token(-1);
                                throw new ParseException();
                        }
                        op = new GeneralComp(gcmp, expr);
                        break;
                    case GtGt:
                    case Is:
                    case LtLt:
                        final NodeComp.Operator ncmp;
                        switch(jj_nt.kind) {
                            case Is:
                                // "is" | "<<" | ">>"
                                currentToken = jj_consume_token(Is);
                                ncmp = NodeComp.Operator.IS;
                                break;
                            case LtLt:
                                currentToken = jj_consume_token(LtLt);
                                ncmp = NodeComp.Operator.PRECEDES;
                                break;
                            case GtGt:
                                currentToken = jj_consume_token(GtGt);
                                ncmp = NodeComp.Operator.FOLLOWS;
                                break;
                            default:
                                jj_la1[89] = jj_gen;
                                jj_consume_token(-1);
                                throw new ParseException();
                        }
                        op = new NodeComp(ncmp, expr);
                        break;
                    default:
                        jj_la1[90] = jj_gen;
                        jj_consume_token(-1);
                        throw new ParseException();
                }
                rightExpr = parseRangeExpr();
                op.setRightOperand(rightExpr);
                expr = locate(op);
                break;
            default:
                jj_la1[91] = jj_gen;
                ;
View Full Code Here

TOP

Related Classes of xbird.xquery.expr.comp.ComparisonOp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.