jdk.nashorn.internal.runtime.regexp.joni.constants.NodeType Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.regexp.joni.constants.NodeType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Parser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(final TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    }
    final ConsAltNode top = ConsAltNode.newListNode(node, null);
    ConsAltNode t = top;

    while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
        node = parseExp(term);
        if (node.getType() == NodeType.LIST) {
            t.setCdr((ConsAltNode)node);
            while (((ConsAltNode)node).cdr != null ) {
                node = ((ConsAltNode)node).cdr;
            }

            t = ((ConsAltNode)node);
        } else {
            t.setCdr(ConsAltNode.newListNode(node, null));
            t = t.cdr;
        }
    }
    return top;
}
 
Example #2
Source File: Parser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(final TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    }
    final ConsAltNode top = ConsAltNode.newListNode(node, null);
    ConsAltNode t = top;

    while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
        node = parseExp(term);
        if (node.getType() == NodeType.LIST) {
            t.setCdr((ConsAltNode)node);
            while (((ConsAltNode)node).cdr != null ) {
                node = ((ConsAltNode)node).cdr;
            }

            t = ((ConsAltNode)node);
        } else {
            t.setCdr(ConsAltNode.newListNode(node, null));
            t = t.cdr;
        }
    }
    return top;
}
 
Example #3
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(final TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    }
    final ConsAltNode top = ConsAltNode.newListNode(node, null);
    ConsAltNode t = top;

    while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
        node = parseExp(term);
        if (node.getType() == NodeType.LIST) {
            t.setCdr((ConsAltNode)node);
            while (((ConsAltNode)node).cdr != null ) {
                node = ((ConsAltNode)node).cdr;
            }

            t = ((ConsAltNode)node);
        } else {
            t.setCdr(ConsAltNode.newListNode(node, null));
            t = t.cdr;
        }
    }
    return top;
}
 
Example #4
Source File: Parser.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    } else {
        ConsAltNode top = ConsAltNode.newListNode(node, null);
        ConsAltNode t = top;

        while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
            node = parseExp(term);
            if (node.getType() == NodeType.LIST) {
                t.setCdr((ConsAltNode)node);
                while (((ConsAltNode)node).cdr != null ) node = ((ConsAltNode)node).cdr;

                t = ((ConsAltNode)node);
            } else {
                t.setCdr(ConsAltNode.newListNode(node, null));
                t = t.cdr;
            }
        }
        return top;
    }
}
 
Example #5
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    } else {
        ConsAltNode top = ConsAltNode.newListNode(node, null);
        ConsAltNode t = top;

        while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
            node = parseExp(term);
            if (node.getType() == NodeType.LIST) {
                t.setCdr((ConsAltNode)node);
                while (((ConsAltNode)node).cdr != null ) node = ((ConsAltNode)node).cdr;

                t = ((ConsAltNode)node);
            } else {
                t.setCdr(ConsAltNode.newListNode(node, null));
                t = t.cdr;
            }
        }
        return top;
    }
}
 
Example #6
Source File: Parser.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(final TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    }
    final ConsAltNode top = ConsAltNode.newListNode(node, null);
    ConsAltNode t = top;

    while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
        node = parseExp(term);
        if (node.getType() == NodeType.LIST) {
            t.setCdr((ConsAltNode)node);
            while (((ConsAltNode)node).cdr != null ) {
                node = ((ConsAltNode)node).cdr;
            }

            t = ((ConsAltNode)node);
        } else {
            t.setCdr(ConsAltNode.newListNode(node, null));
            t = t.cdr;
        }
    }
    return top;
}
 
Example #7
Source File: Parser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(final TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    }
    final ConsAltNode top = ConsAltNode.newListNode(node, null);
    ConsAltNode t = top;

    while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
        node = parseExp(term);
        if (node.getType() == NodeType.LIST) {
            t.setCdr((ConsAltNode)node);
            while (((ConsAltNode)node).cdr != null ) {
                node = ((ConsAltNode)node).cdr;
            }

            t = ((ConsAltNode)node);
        } else {
            t.setCdr(ConsAltNode.newListNode(node, null));
            t = t.cdr;
        }
    }
    return top;
}
 
Example #8
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(final TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    }
    final ConsAltNode top = ConsAltNode.newListNode(node, null);
    ConsAltNode t = top;

    while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
        node = parseExp(term);
        if (node.getType() == NodeType.LIST) {
            t.setCdr((ConsAltNode)node);
            while (((ConsAltNode)node).cdr != null ) {
                node = ((ConsAltNode)node).cdr;
            }

            t = ((ConsAltNode)node);
        } else {
            t.setCdr(ConsAltNode.newListNode(node, null));
            t = t.cdr;
        }
    }
    return top;
}
 
Example #9
Source File: Parser.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    } else {
        ConsAltNode top = ConsAltNode.newListNode(node, null);
        ConsAltNode t = top;

        while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
            node = parseExp(term);
            if (node.getType() == NodeType.LIST) {
                t.setCdr((ConsAltNode)node);
                while (((ConsAltNode)node).cdr != null ) node = ((ConsAltNode)node).cdr;

                t = ((ConsAltNode)node);
            } else {
                t.setCdr(ConsAltNode.newListNode(node, null));
                t = t.cdr;
            }
        }
        return top;
    }
}
 
Example #10
Source File: Parser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(final TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    }
    final ConsAltNode top = ConsAltNode.newListNode(node, null);
    ConsAltNode t = top;

    while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
        node = parseExp(term);
        if (node.getType() == NodeType.LIST) {
            t.setCdr((ConsAltNode)node);
            while (((ConsAltNode)node).cdr != null ) {
                node = ((ConsAltNode)node).cdr;
            }

            t = ((ConsAltNode)node);
        } else {
            t.setCdr(ConsAltNode.newListNode(node, null));
            t = t.cdr;
        }
    }
    return top;
}
 
Example #11
Source File: Analyser.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkTypeTree(Node node, int typeMask, int encloseMask, int anchorMask) {
    if ((node.getType2Bit() & typeMask) == 0) return true;

    boolean invalid = false;

    switch(node.getType()) {
    case NodeType.LIST:
    case NodeType.ALT:
        ConsAltNode can = (ConsAltNode)node;
        do {
            invalid = checkTypeTree(can.car, typeMask, encloseMask, anchorMask);
        } while (!invalid && (can = can.cdr) != null);
        break;

    case NodeType.QTFR:
        invalid = checkTypeTree(((QuantifierNode)node).target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ENCLOSE:
        EncloseNode en = (EncloseNode)node;
        if ((en.type & encloseMask) == 0) return true;
        invalid = checkTypeTree(en.target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ANCHOR:
        AnchorNode an = (AnchorNode)node;
        if ((an.type & anchorMask) == 0) return true;

        if (an.target != null) invalid = checkTypeTree(an.target, typeMask, encloseMask, anchorMask);
        break;

    default:
        break;

    } // switch

    return invalid;
}
 
Example #12
Source File: Analyser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkTypeTree(Node node, int typeMask, int encloseMask, int anchorMask) {
    if ((node.getType2Bit() & typeMask) == 0) return true;

    boolean invalid = false;

    switch(node.getType()) {
    case NodeType.LIST:
    case NodeType.ALT:
        ConsAltNode can = (ConsAltNode)node;
        do {
            invalid = checkTypeTree(can.car, typeMask, encloseMask, anchorMask);
        } while (!invalid && (can = can.cdr) != null);
        break;

    case NodeType.QTFR:
        invalid = checkTypeTree(((QuantifierNode)node).target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ENCLOSE:
        EncloseNode en = (EncloseNode)node;
        if ((en.type & encloseMask) == 0) return true;
        invalid = checkTypeTree(en.target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ANCHOR:
        AnchorNode an = (AnchorNode)node;
        if ((an.type & anchorMask) == 0) return true;

        if (an.target != null) invalid = checkTypeTree(an.target, typeMask, encloseMask, anchorMask);
        break;

    default:
        break;

    } // switch

    return invalid;
}
 
Example #13
Source File: Analyser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkTypeTree(Node node, int typeMask, int encloseMask, int anchorMask) {
    if ((node.getType2Bit() & typeMask) == 0) return true;

    boolean invalid = false;

    switch(node.getType()) {
    case NodeType.LIST:
    case NodeType.ALT:
        ConsAltNode can = (ConsAltNode)node;
        do {
            invalid = checkTypeTree(can.car, typeMask, encloseMask, anchorMask);
        } while (!invalid && (can = can.cdr) != null);
        break;

    case NodeType.QTFR:
        invalid = checkTypeTree(((QuantifierNode)node).target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ENCLOSE:
        EncloseNode en = (EncloseNode)node;
        if ((en.type & encloseMask) == 0) return true;
        invalid = checkTypeTree(en.target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ANCHOR:
        AnchorNode an = (AnchorNode)node;
        if ((an.type & anchorMask) == 0) return true;

        if (an.target != null) invalid = checkTypeTree(an.target, typeMask, encloseMask, anchorMask);
        break;

    default:
        break;

    } // switch

    return invalid;
}
 
Example #14
Source File: Compiler.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
protected final void compileTree(Node node) {
    switch (node.getType()) {
    case NodeType.LIST:
        ConsAltNode lin = (ConsAltNode)node;
        do {
            compileTree(lin.car);
        } while ((lin = lin.cdr) != null);
        break;

    case NodeType.ALT:
        compileAltNode((ConsAltNode)node);
        break;

    case NodeType.STR:
        StringNode sn = (StringNode)node;
        if (sn.isRaw()) {
            compileStringRawNode(sn);
        } else {
            compileStringNode(sn);
        }
        break;

    case NodeType.CCLASS:
        compileCClassNode((CClassNode)node);
        break;

    case NodeType.CANY:
        compileAnyCharNode();
        break;

    case NodeType.BREF:
        compileBackrefNode((BackRefNode)node);
        break;

    case NodeType.QTFR:
        compileNonCECQuantifierNode((QuantifierNode)node);
        break;

    case NodeType.ENCLOSE:
        EncloseNode enode = (EncloseNode)node;
        if (enode.isOption()) {
            compileOptionNode(enode);
        } else {
            compileEncloseNode(enode);
        }
        break;

    case NodeType.ANCHOR:
        compileAnchorNode((AnchorNode)node);
        break;

    default:
        // undefined node type
        newInternalException(ERR_PARSER_BUG);
    } // switch
}
 
Example #15
Source File: Analyser.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
private boolean checkTypeTree(final Node node, final int typeMask, final int encloseMask, final int anchorMask) {
    if ((node.getType2Bit() & typeMask) == 0) {
        return true;
    }

    boolean invalid = false;

    switch(node.getType()) {
    case NodeType.LIST:
    case NodeType.ALT:
        ConsAltNode can = (ConsAltNode)node;
        do {
            invalid = checkTypeTree(can.car, typeMask, encloseMask, anchorMask);
        } while (!invalid && (can = can.cdr) != null);
        break;

    case NodeType.QTFR:
        invalid = checkTypeTree(((QuantifierNode)node).target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ENCLOSE:
        final EncloseNode en = (EncloseNode)node;
        if ((en.type & encloseMask) == 0) {
            return true;
        }
        invalid = checkTypeTree(en.target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ANCHOR:
        final AnchorNode an = (AnchorNode)node;
        if ((an.type & anchorMask) == 0) {
            return true;
        }

        if (an.target != null) {
            invalid = checkTypeTree(an.target, typeMask, encloseMask, anchorMask);
        }
        break;

    default:
        break;

    } // switch

    return invalid;
}
 
Example #16
Source File: ArrayCompiler.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private int compileNonCECLengthQuantifierNode(QuantifierNode qn) {
    boolean infinite = isRepeatInfinite(qn.upper);
    int emptyInfo = qn.targetEmptyInfo;

    int tlen = compileLengthTree(qn.target);

    /* anychar repeat */
    if (qn.target.getType() == NodeType.CANY) {
        if (qn.greedy && infinite) {
            if (qn.nextHeadExact != null) {
                return OPSize.ANYCHAR_STAR_PEEK_NEXT + tlen * qn.lower;
            } else {
                return OPSize.ANYCHAR_STAR + tlen * qn.lower;
            }
        }
    }

    int modTLen = 0;
    if (emptyInfo != 0) {
        modTLen = tlen + (OPSize.NULL_CHECK_START + OPSize.NULL_CHECK_END);
    } else {
        modTLen = tlen;
    }

    int len;
    if (infinite && (qn.lower <= 1 || tlen * qn.lower <= QUANTIFIER_EXPAND_LIMIT_SIZE)) {
        if (qn.lower == 1 && tlen > QUANTIFIER_EXPAND_LIMIT_SIZE) {
            len = OPSize.JUMP;
        } else {
            len = tlen * qn.lower;
        }

        if (qn.greedy) {
            if (qn.headExact != null) {
                len += OPSize.PUSH_OR_JUMP_EXACT1 + modTLen + OPSize.JUMP;
            } else if (qn.nextHeadExact != null) {
                len += OPSize.PUSH_IF_PEEK_NEXT + modTLen + OPSize.JUMP;
            } else {
                len += OPSize.PUSH + modTLen + OPSize.JUMP;
            }
        } else {
            len += OPSize.JUMP + modTLen + OPSize.PUSH;
        }

    } else if (qn.upper == 0 && qn.isRefered) { /* /(?<n>..){0}/ */
        len = OPSize.JUMP + tlen;
    } else if (!infinite && qn.greedy &&
              (qn.upper == 1 || (tlen + OPSize.PUSH) * qn.upper <= QUANTIFIER_EXPAND_LIMIT_SIZE )) {
        len = tlen * qn.lower;
        len += (OPSize.PUSH + tlen) * (qn.upper - qn.lower);
    } else if (!qn.greedy && qn.upper == 1 && qn.lower == 0) { /* '??' */
        len = OPSize.PUSH + OPSize.JUMP + tlen;
    } else {
        len = OPSize.REPEAT_INC + modTLen + OPSize.OPCODE + OPSize.RELADDR + OPSize.MEMNUM;
    }
    return len;
}
 
Example #17
Source File: Compiler.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
protected final void compileTree(Node node) {
    switch (node.getType()) {
    case NodeType.LIST:
        ConsAltNode lin = (ConsAltNode)node;
        do {
            compileTree(lin.car);
        } while ((lin = lin.cdr) != null);
        break;

    case NodeType.ALT:
        compileAltNode((ConsAltNode)node);
        break;

    case NodeType.STR:
        StringNode sn = (StringNode)node;
        if (sn.isRaw()) {
            compileStringRawNode(sn);
        } else {
            compileStringNode(sn);
        }
        break;

    case NodeType.CCLASS:
        compileCClassNode((CClassNode)node);
        break;

    case NodeType.CANY:
        compileAnyCharNode();
        break;

    case NodeType.BREF:
        compileBackrefNode((BackRefNode)node);
        break;

    case NodeType.QTFR:
        compileNonCECQuantifierNode((QuantifierNode)node);
        break;

    case NodeType.ENCLOSE:
        EncloseNode enode = (EncloseNode)node;
        if (enode.isOption()) {
            compileOptionNode(enode);
        } else {
            compileEncloseNode(enode);
        }
        break;

    case NodeType.ANCHOR:
        compileAnchorNode((AnchorNode)node);
        break;

    default:
        // undefined node type
        newInternalException(ERR_PARSER_BUG);
    } // switch
}
 
Example #18
Source File: ArrayCompiler.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private int compileLengthTree(Node node) {
    int len = 0;

    switch (node.getType()) {
    case NodeType.LIST:
        ConsAltNode lin = (ConsAltNode)node;
        do {
            len += compileLengthTree(lin.car);
        } while ((lin = lin.cdr) != null);
        break;

    case NodeType.ALT:
        ConsAltNode aln = (ConsAltNode)node;
        int n = 0;
        do {
            len += compileLengthTree(aln.car);
            n++;
        } while ((aln = aln.cdr) != null);
        len += (OPSize.PUSH + OPSize.JUMP) * (n - 1);
        break;

    case NodeType.STR:
        StringNode sn = (StringNode)node;
        if (sn.isRaw()) {
            len = compileLengthStringRawNode(sn);
        } else {
            len = compileLengthStringNode(sn);
        }
        break;

    case NodeType.CCLASS:
        len = compileLengthCClassNode((CClassNode)node);
        break;

    case NodeType.CTYPE:
    case NodeType.CANY:
        len = OPSize.OPCODE;
        break;

    case NodeType.BREF:
        BackRefNode br = (BackRefNode)node;

        len = ((!isIgnoreCase(regex.options) && br.backRef <= 2)
                ? OPSize.OPCODE : (OPSize.OPCODE + OPSize.MEMNUM));
        break;

    case NodeType.QTFR:
        len = compileNonCECLengthQuantifierNode((QuantifierNode)node);
        break;

    case NodeType.ENCLOSE:
        len = compileLengthEncloseNode((EncloseNode)node);
        break;

    case NodeType.ANCHOR:
        len = compileLengthAnchorNode((AnchorNode)node);
        break;

    default:
        newInternalException(ERR_PARSER_BUG);

    } //switch
    return len;
}
 
Example #19
Source File: Analyser.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private int getMinMatchLength(final Node node) {
    int min = 0;

    switch (node.getType()) {
    case NodeType.BREF:
        final BackRefNode br = (BackRefNode)node;
        if (br.isRecursion()) {
            break;
        }

        if (br.backRef > env.numMem) {
            throw new ValueException(ERR_INVALID_BACKREF);
        }
        min = getMinMatchLength(env.memNodes[br.backRef]);

        break;

    case NodeType.LIST:
        ConsAltNode can = (ConsAltNode)node;
        do {
            min += getMinMatchLength(can.car);
        } while ((can = can.cdr) != null);
        break;

    case NodeType.ALT:
        ConsAltNode y = (ConsAltNode)node;
        do {
            final Node x = y.car;
            final int tmin = getMinMatchLength(x);
            if (y == node) {
                min = tmin;
            } else if (min > tmin) {
                min = tmin;
            }
        } while ((y = y.cdr) != null);
        break;

    case NodeType.STR:
        min = ((StringNode)node).length();
        break;

    case NodeType.CTYPE:
        min = 1;
        break;

    case NodeType.CCLASS:
    case NodeType.CANY:
        min = 1;
        break;

    case NodeType.QTFR:
        final QuantifierNode qn = (QuantifierNode)node;
        if (qn.lower > 0) {
            min = getMinMatchLength(qn.target);
            min = MinMaxLen.distanceMultiply(min, qn.lower);
        }
        break;

    case NodeType.ENCLOSE:
        final EncloseNode en = (EncloseNode)node;
        switch (en.type) {
        case EncloseType.MEMORY:
            if (en.isMinFixed()) {
                min = en.minLength;
            } else {
                min = getMinMatchLength(en.target);
                en.minLength = min;
                en.setMinFixed();
            }
            break;

        case EncloseType.OPTION:
        case EncloseType.STOP_BACKTRACK:
            min = getMinMatchLength(en.target);
            break;

        default:
            break;
        } // inner switch
        break;

    case NodeType.ANCHOR:
    default:
        break;
    } // switch

    return min;
}
 
Example #20
Source File: Analyser.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private int getMinMatchLength(Node node) {
    int min = 0;

    switch (node.getType()) {
    case NodeType.BREF:
        BackRefNode br = (BackRefNode)node;
        if (br.isRecursion()) break;

        if (br.backRef > env.numMem) {
            throw new ValueException(ERR_INVALID_BACKREF);
        }
        min = getMinMatchLength(env.memNodes[br.backRef]);

        break;

    case NodeType.LIST:
        ConsAltNode can = (ConsAltNode)node;
        do {
            min += getMinMatchLength(can.car);
        } while ((can = can.cdr) != null);
        break;

    case NodeType.ALT:
        ConsAltNode y = (ConsAltNode)node;
        do {
            Node x = y.car;
            int tmin = getMinMatchLength(x);
            if (y == node) {
                min = tmin;
            } else if (min > tmin) {
                min = tmin;
            }
        } while ((y = y.cdr) != null);
        break;

    case NodeType.STR:
        min = ((StringNode)node).length();
        break;

    case NodeType.CTYPE:
        min = 1;
        break;

    case NodeType.CCLASS:
    case NodeType.CANY:
        min = 1;
        break;

    case NodeType.QTFR:
        QuantifierNode qn = (QuantifierNode)node;
        if (qn.lower > 0) {
            min = getMinMatchLength(qn.target);
            min = MinMaxLen.distanceMultiply(min, qn.lower);
        }
        break;

    case NodeType.ENCLOSE:
        EncloseNode en = (EncloseNode)node;
        switch (en.type) {
        case EncloseType.MEMORY:
            if (en.isMinFixed()) {
                min = en.minLength;
            } else {
                min = getMinMatchLength(en.target);
                en.minLength = min;
                en.setMinFixed();
            }
            break;

        case EncloseType.OPTION:
        case EncloseType.STOP_BACKTRACK:
            min = getMinMatchLength(en.target);
            break;
        } // inner switch
        break;

    case NodeType.ANCHOR:
    default:
        break;
    } // switch

    return min;
}
 
Example #21
Source File: ArrayCompiler.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private int compileLengthTree(Node node) {
    int len = 0;

    switch (node.getType()) {
    case NodeType.LIST:
        ConsAltNode lin = (ConsAltNode)node;
        do {
            len += compileLengthTree(lin.car);
        } while ((lin = lin.cdr) != null);
        break;

    case NodeType.ALT:
        ConsAltNode aln = (ConsAltNode)node;
        int n = 0;
        do {
            len += compileLengthTree(aln.car);
            n++;
        } while ((aln = aln.cdr) != null);
        len += (OPSize.PUSH + OPSize.JUMP) * (n - 1);
        break;

    case NodeType.STR:
        StringNode sn = (StringNode)node;
        if (sn.isRaw()) {
            len = compileLengthStringRawNode(sn);
        } else {
            len = compileLengthStringNode(sn);
        }
        break;

    case NodeType.CCLASS:
        len = compileLengthCClassNode((CClassNode)node);
        break;

    case NodeType.CTYPE:
    case NodeType.CANY:
        len = OPSize.OPCODE;
        break;

    case NodeType.BREF:
        BackRefNode br = (BackRefNode)node;

        len = ((!isIgnoreCase(regex.options) && br.backRef <= 2)
                ? OPSize.OPCODE : (OPSize.OPCODE + OPSize.MEMNUM));
        break;

    case NodeType.QTFR:
        len = compileNonCECLengthQuantifierNode((QuantifierNode)node);
        break;

    case NodeType.ENCLOSE:
        len = compileLengthEncloseNode((EncloseNode)node);
        break;

    case NodeType.ANCHOR:
        len = compileLengthAnchorNode((AnchorNode)node);
        break;

    default:
        newInternalException(ERR_PARSER_BUG);

    } //switch
    return len;
}
 
Example #22
Source File: ArrayCompiler.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private int compileNonCECLengthQuantifierNode(QuantifierNode qn) {
    boolean infinite = isRepeatInfinite(qn.upper);
    int emptyInfo = qn.targetEmptyInfo;

    int tlen = compileLengthTree(qn.target);

    /* anychar repeat */
    if (qn.target.getType() == NodeType.CANY) {
        if (qn.greedy && infinite) {
            if (qn.nextHeadExact != null) {
                return OPSize.ANYCHAR_STAR_PEEK_NEXT + tlen * qn.lower;
            } else {
                return OPSize.ANYCHAR_STAR + tlen * qn.lower;
            }
        }
    }

    int modTLen = 0;
    if (emptyInfo != 0) {
        modTLen = tlen + (OPSize.NULL_CHECK_START + OPSize.NULL_CHECK_END);
    } else {
        modTLen = tlen;
    }

    int len;
    if (infinite && (qn.lower <= 1 || tlen * qn.lower <= QUANTIFIER_EXPAND_LIMIT_SIZE)) {
        if (qn.lower == 1 && tlen > QUANTIFIER_EXPAND_LIMIT_SIZE) {
            len = OPSize.JUMP;
        } else {
            len = tlen * qn.lower;
        }

        if (qn.greedy) {
            if (qn.headExact != null) {
                len += OPSize.PUSH_OR_JUMP_EXACT1 + modTLen + OPSize.JUMP;
            } else if (qn.nextHeadExact != null) {
                len += OPSize.PUSH_IF_PEEK_NEXT + modTLen + OPSize.JUMP;
            } else {
                len += OPSize.PUSH + modTLen + OPSize.JUMP;
            }
        } else {
            len += OPSize.JUMP + modTLen + OPSize.PUSH;
        }

    } else if (qn.upper == 0 && qn.isRefered) { /* /(?<n>..){0}/ */
        len = OPSize.JUMP + tlen;
    } else if (!infinite && qn.greedy &&
              (qn.upper == 1 || (tlen + OPSize.PUSH) * qn.upper <= QUANTIFIER_EXPAND_LIMIT_SIZE )) {
        len = tlen * qn.lower;
        len += (OPSize.PUSH + tlen) * (qn.upper - qn.lower);
    } else if (!qn.greedy && qn.upper == 1 && qn.lower == 0) { /* '??' */
        len = OPSize.PUSH + OPSize.JUMP + tlen;
    } else {
        len = OPSize.REPEAT_INC + modTLen + OPSize.OPCODE + OPSize.RELADDR + OPSize.MEMNUM;
    }
    return len;
}
 
Example #23
Source File: Analyser.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private boolean isNotIncluded(Node x, Node y) {
    Node tmp;

    // !retry:!
    retry: while(true) {

    int yType = y.getType();

    switch(x.getType()) {
    case NodeType.CTYPE:
        switch(yType) {

        case NodeType.CCLASS:
            // !swap:!
            tmp = x;
            x = y;
            y = tmp;
            // !goto retry;!
            continue retry;

        case NodeType.STR:
            // !goto swap;!
            tmp = x;
            x = y;
            y = tmp;
            continue retry;

        default:
            break;
        } // inner switch
        break;

    case NodeType.CCLASS:
        CClassNode xc = (CClassNode)x;

        switch(yType) {

        case NodeType.CCLASS:
            CClassNode yc = (CClassNode)y;

            for (int i=0; i<BitSet.SINGLE_BYTE_SIZE; i++) {
                boolean v = xc.bs.at(i);
                if ((v && !xc.isNot()) || (!v && xc.isNot())) {
                    v = yc.bs.at(i);
                    if ((v && !yc.isNot()) || (!v && yc.isNot())) return false;
                }
            }
            if ((xc.mbuf == null && !xc.isNot()) || yc.mbuf == null && !yc.isNot()) return true;
            return false;
            // break; not reached

        case NodeType.STR:
            // !goto swap;!
            tmp = x;
            x = y;
            y = tmp;
            continue retry;

        default:
            break;

        } // inner switch
        break; // case NodeType.CCLASS

    case NodeType.STR:
        StringNode xs = (StringNode)x;
        if (xs.length() == 0) break;

        switch (yType) {

        case NodeType.CCLASS:
            CClassNode cc = (CClassNode)y;
            int code = xs.chars[xs.p];
            return !cc.isCodeInCC(code);

        case NodeType.STR:
            StringNode ys = (StringNode)y;
            int len = xs.length();
            if (len > ys.length()) len = ys.length();
            if (xs.isAmbig() || ys.isAmbig()) {
                /* tiny version */
                return false;
            } else {
                for (int i=0, p=ys.p, q=xs.p; i<len; i++, p++, q++) {
                    if (ys.chars[p] != xs.chars[q]) return true;
                }
            }
            break;

        default:
            break;
        } // inner switch

        break; // case NodeType.STR

    } // switch

    break;
    } // retry: while
    return false;
}
 
Example #24
Source File: Analyser.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private int getMinMatchLength(Node node) {
    int min = 0;

    switch (node.getType()) {
    case NodeType.BREF:
        BackRefNode br = (BackRefNode)node;
        if (br.isRecursion()) break;

        if (br.backRef > env.numMem) {
            throw new ValueException(ERR_INVALID_BACKREF);
        }
        min = getMinMatchLength(env.memNodes[br.backRef]);

        break;

    case NodeType.LIST:
        ConsAltNode can = (ConsAltNode)node;
        do {
            min += getMinMatchLength(can.car);
        } while ((can = can.cdr) != null);
        break;

    case NodeType.ALT:
        ConsAltNode y = (ConsAltNode)node;
        do {
            Node x = y.car;
            int tmin = getMinMatchLength(x);
            if (y == node) {
                min = tmin;
            } else if (min > tmin) {
                min = tmin;
            }
        } while ((y = y.cdr) != null);
        break;

    case NodeType.STR:
        min = ((StringNode)node).length();
        break;

    case NodeType.CTYPE:
        min = 1;
        break;

    case NodeType.CCLASS:
    case NodeType.CANY:
        min = 1;
        break;

    case NodeType.QTFR:
        QuantifierNode qn = (QuantifierNode)node;
        if (qn.lower > 0) {
            min = getMinMatchLength(qn.target);
            min = MinMaxLen.distanceMultiply(min, qn.lower);
        }
        break;

    case NodeType.ENCLOSE:
        EncloseNode en = (EncloseNode)node;
        switch (en.type) {
        case EncloseType.MEMORY:
            if (en.isMinFixed()) {
                min = en.minLength;
            } else {
                min = getMinMatchLength(en.target);
                en.minLength = min;
                en.setMinFixed();
            }
            break;

        case EncloseType.OPTION:
        case EncloseType.STOP_BACKTRACK:
            min = getMinMatchLength(en.target);
            break;
        } // inner switch
        break;

    case NodeType.ANCHOR:
    default:
        break;
    } // switch

    return min;
}
 
Example #25
Source File: Analyser.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private int quantifiersMemoryInfo(Node node) {
    int info = 0;

    switch(node.getType()) {
    case NodeType.LIST:
    case NodeType.ALT:
        ConsAltNode can = (ConsAltNode)node;
        do {
            int v = quantifiersMemoryInfo(can.car);
            if (v > info) info = v;
        } while ((can = can.cdr) != null);
        break;

    case NodeType.QTFR:
        QuantifierNode qn = (QuantifierNode)node;
        if (qn.upper != 0) {
            info = quantifiersMemoryInfo(qn.target);
        }
        break;

    case NodeType.ENCLOSE:
        EncloseNode en = (EncloseNode)node;
        switch (en.type) {
        case EncloseType.MEMORY:
            return TargetInfo.IS_EMPTY_MEM;

        case EncloseType.OPTION:
        case EncloseNode.STOP_BACKTRACK:
            info = quantifiersMemoryInfo(en.target);
            break;

        default:
            break;
        } // inner switch
        break;

    case NodeType.BREF:
    case NodeType.STR:
    case NodeType.CTYPE:
    case NodeType.CCLASS:
    case NodeType.CANY:
    case NodeType.ANCHOR:
    default:
        break;
    } // switch

    return info;
}
 
Example #26
Source File: Compiler.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
protected final void compileTree(Node node) {
    switch (node.getType()) {
    case NodeType.LIST:
        ConsAltNode lin = (ConsAltNode)node;
        do {
            compileTree(lin.car);
        } while ((lin = lin.cdr) != null);
        break;

    case NodeType.ALT:
        compileAltNode((ConsAltNode)node);
        break;

    case NodeType.STR:
        StringNode sn = (StringNode)node;
        if (sn.isRaw()) {
            compileStringRawNode(sn);
        } else {
            compileStringNode(sn);
        }
        break;

    case NodeType.CCLASS:
        compileCClassNode((CClassNode)node);
        break;

    case NodeType.CANY:
        compileAnyCharNode();
        break;

    case NodeType.BREF:
        compileBackrefNode((BackRefNode)node);
        break;

    case NodeType.QTFR:
        compileNonCECQuantifierNode((QuantifierNode)node);
        break;

    case NodeType.ENCLOSE:
        EncloseNode enode = (EncloseNode)node;
        if (enode.isOption()) {
            compileOptionNode(enode);
        } else {
            compileEncloseNode(enode);
        }
        break;

    case NodeType.ANCHOR:
        compileAnchorNode((AnchorNode)node);
        break;

    default:
        // undefined node type
        newInternalException(ERR_PARSER_BUG);
    } // switch
}
 
Example #27
Source File: ArrayCompiler.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private int compileLengthTree(Node node) {
    int len = 0;

    switch (node.getType()) {
    case NodeType.LIST:
        ConsAltNode lin = (ConsAltNode)node;
        do {
            len += compileLengthTree(lin.car);
        } while ((lin = lin.cdr) != null);
        break;

    case NodeType.ALT:
        ConsAltNode aln = (ConsAltNode)node;
        int n = 0;
        do {
            len += compileLengthTree(aln.car);
            n++;
        } while ((aln = aln.cdr) != null);
        len += (OPSize.PUSH + OPSize.JUMP) * (n - 1);
        break;

    case NodeType.STR:
        StringNode sn = (StringNode)node;
        if (sn.isRaw()) {
            len = compileLengthStringRawNode(sn);
        } else {
            len = compileLengthStringNode(sn);
        }
        break;

    case NodeType.CCLASS:
        len = compileLengthCClassNode((CClassNode)node);
        break;

    case NodeType.CTYPE:
    case NodeType.CANY:
        len = OPSize.OPCODE;
        break;

    case NodeType.BREF:
        BackRefNode br = (BackRefNode)node;

        len = ((!isIgnoreCase(regex.options) && br.backRef <= 2)
                ? OPSize.OPCODE : (OPSize.OPCODE + OPSize.MEMNUM));
        break;

    case NodeType.QTFR:
        len = compileNonCECLengthQuantifierNode((QuantifierNode)node);
        break;

    case NodeType.ENCLOSE:
        len = compileLengthEncloseNode((EncloseNode)node);
        break;

    case NodeType.ANCHOR:
        len = compileLengthAnchorNode((AnchorNode)node);
        break;

    default:
        newInternalException(ERR_PARSER_BUG);

    } //switch
    return len;
}
 
Example #28
Source File: ArrayCompiler.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private int compileNonCECLengthQuantifierNode(QuantifierNode qn) {
    boolean infinite = isRepeatInfinite(qn.upper);
    int emptyInfo = qn.targetEmptyInfo;

    int tlen = compileLengthTree(qn.target);

    /* anychar repeat */
    if (qn.target.getType() == NodeType.CANY) {
        if (qn.greedy && infinite) {
            if (qn.nextHeadExact != null) {
                return OPSize.ANYCHAR_STAR_PEEK_NEXT + tlen * qn.lower;
            } else {
                return OPSize.ANYCHAR_STAR + tlen * qn.lower;
            }
        }
    }

    int modTLen = 0;
    if (emptyInfo != 0) {
        modTLen = tlen + (OPSize.NULL_CHECK_START + OPSize.NULL_CHECK_END);
    } else {
        modTLen = tlen;
    }

    int len;
    if (infinite && (qn.lower <= 1 || tlen * qn.lower <= QUANTIFIER_EXPAND_LIMIT_SIZE)) {
        if (qn.lower == 1 && tlen > QUANTIFIER_EXPAND_LIMIT_SIZE) {
            len = OPSize.JUMP;
        } else {
            len = tlen * qn.lower;
        }

        if (qn.greedy) {
            if (qn.headExact != null) {
                len += OPSize.PUSH_OR_JUMP_EXACT1 + modTLen + OPSize.JUMP;
            } else if (qn.nextHeadExact != null) {
                len += OPSize.PUSH_IF_PEEK_NEXT + modTLen + OPSize.JUMP;
            } else {
                len += OPSize.PUSH + modTLen + OPSize.JUMP;
            }
        } else {
            len += OPSize.JUMP + modTLen + OPSize.PUSH;
        }

    } else if (qn.upper == 0 && qn.isRefered) { /* /(?<n>..){0}/ */
        len = OPSize.JUMP + tlen;
    } else if (!infinite && qn.greedy &&
              (qn.upper == 1 || (tlen + OPSize.PUSH) * qn.upper <= QUANTIFIER_EXPAND_LIMIT_SIZE )) {
        len = tlen * qn.lower;
        len += (OPSize.PUSH + tlen) * (qn.upper - qn.lower);
    } else if (!qn.greedy && qn.upper == 1 && qn.lower == 0) { /* '??' */
        len = OPSize.PUSH + OPSize.JUMP + tlen;
    } else {
        len = OPSize.REPEAT_INC + modTLen + OPSize.OPCODE + OPSize.RELADDR + OPSize.MEMNUM;
    }
    return len;
}
 
Example #29
Source File: Analyser.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private boolean checkTypeTree(final Node node, final int typeMask, final int encloseMask, final int anchorMask) {
    if ((node.getType2Bit() & typeMask) == 0) {
        return true;
    }

    boolean invalid = false;

    switch(node.getType()) {
    case NodeType.LIST:
    case NodeType.ALT:
        ConsAltNode can = (ConsAltNode)node;
        do {
            invalid = checkTypeTree(can.car, typeMask, encloseMask, anchorMask);
        } while (!invalid && (can = can.cdr) != null);
        break;

    case NodeType.QTFR:
        invalid = checkTypeTree(((QuantifierNode)node).target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ENCLOSE:
        final EncloseNode en = (EncloseNode)node;
        if ((en.type & encloseMask) == 0) {
            return true;
        }
        invalid = checkTypeTree(en.target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ANCHOR:
        final AnchorNode an = (AnchorNode)node;
        if ((an.type & anchorMask) == 0) {
            return true;
        }

        if (an.target != null) {
            invalid = checkTypeTree(an.target, typeMask, encloseMask, anchorMask);
        }
        break;

    default:
        break;

    } // switch

    return invalid;
}
 
Example #30
Source File: ArrayCompiler.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private int compileLengthTree(final Node node) {
    int len = 0;

    switch (node.getType()) {
    case NodeType.LIST:
        ConsAltNode lin = (ConsAltNode)node;
        do {
            len += compileLengthTree(lin.car);
        } while ((lin = lin.cdr) != null);
        break;

    case NodeType.ALT:
        ConsAltNode aln = (ConsAltNode)node;
        int n = 0;
        do {
            len += compileLengthTree(aln.car);
            n++;
        } while ((aln = aln.cdr) != null);
        len += (OPSize.PUSH + OPSize.JUMP) * (n - 1);
        break;

    case NodeType.STR:
        final StringNode sn = (StringNode)node;
        if (sn.isRaw()) {
            len = compileLengthStringRawNode(sn);
        } else {
            len = compileLengthStringNode(sn);
        }
        break;

    case NodeType.CCLASS:
        len = compileLengthCClassNode((CClassNode)node);
        break;

    case NodeType.CTYPE:
    case NodeType.CANY:
        len = OPSize.OPCODE;
        break;

    case NodeType.BREF:
        final BackRefNode br = (BackRefNode)node;

        len = ((!isIgnoreCase(regex.options) && br.backRef <= 2)
                ? OPSize.OPCODE : (OPSize.OPCODE + OPSize.MEMNUM));
        break;

    case NodeType.QTFR:
        len = compileNonCECLengthQuantifierNode((QuantifierNode)node);
        break;

    case NodeType.ENCLOSE:
        len = compileLengthEncloseNode((EncloseNode)node);
        break;

    case NodeType.ANCHOR:
        len = compileLengthAnchorNode((AnchorNode)node);
        break;

    default:
        newInternalException(ERR_PARSER_BUG);

    } //switch
    return len;
}