Java Code Examples for jdk.nashorn.internal.runtime.regexp.joni.constants.OPSize#JUMP

The following examples show how to use jdk.nashorn.internal.runtime.regexp.joni.constants.OPSize#JUMP . 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: ArrayCompiler.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private int compileLengthEncloseNode(EncloseNode node) {
    if (node.isOption()) {
        return compileLengthOptionNode(node);
    }

    int tlen;
    if (node.target != null) {
        tlen = compileLengthTree(node.target);
    } else {
        tlen = 0;
    }

    int len;
    switch (node.type) {
    case EncloseType.MEMORY:
        if (bsAt(regex.btMemStart, node.regNum)) {
            len = OPSize.MEMORY_START_PUSH;
        } else {
            len = OPSize.MEMORY_START;
        }
        len += tlen + (bsAt(regex.btMemEnd, node.regNum) ? OPSize.MEMORY_END_PUSH : OPSize.MEMORY_END);
        break;

    case EncloseType.STOP_BACKTRACK:
        if (node.isStopBtSimpleRepeat()) {
            QuantifierNode qn = (QuantifierNode)node.target;
            tlen = compileLengthTree(qn.target);
            len = tlen * qn.lower + OPSize.PUSH + tlen + OPSize.POP + OPSize.JUMP;
        } else {
            len = OPSize.PUSH_STOP_BT + tlen + OPSize.POP_STOP_BT;
        }
        break;

    default:
        newInternalException(ERR_PARSER_BUG);
        return 0; // not reached
    } // switch
    return len;
}
 
Example 2
Source File: ArrayCompiler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private int compileLengthEncloseNode(final EncloseNode node) {
    if (node.isOption()) {
        return compileLengthOptionNode(node);
    }

    int tlen;
    if (node.target != null) {
        tlen = compileLengthTree(node.target);
    } else {
        tlen = 0;
    }

    int len;
    switch (node.type) {
    case EncloseType.MEMORY:
        if (bsAt(regex.btMemStart, node.regNum)) {
            len = OPSize.MEMORY_START_PUSH;
        } else {
            len = OPSize.MEMORY_START;
        }
        len += tlen + (bsAt(regex.btMemEnd, node.regNum) ? OPSize.MEMORY_END_PUSH : OPSize.MEMORY_END);
        break;

    case EncloseType.STOP_BACKTRACK:
        if (node.isStopBtSimpleRepeat()) {
            final QuantifierNode qn = (QuantifierNode)node.target;
            tlen = compileLengthTree(qn.target);
            len = tlen * qn.lower + OPSize.PUSH + tlen + OPSize.POP + OPSize.JUMP;
        } else {
            len = OPSize.PUSH_STOP_BT + tlen + OPSize.POP_STOP_BT;
        }
        break;

    default:
        newInternalException(ERR_PARSER_BUG);
        return 0; // not reached
    } // switch
    return len;
}
 
Example 3
Source File: ArrayCompiler.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void compileAltNode(final ConsAltNode node) {
    ConsAltNode aln = node;
    int len = 0;

    do {
        len += compileLengthTree(aln.car);
        if (aln.cdr != null) {
            len += OPSize.PUSH + OPSize.JUMP;
        }
    } while ((aln = aln.cdr) != null);

    final int pos = codeLength + len;  /* goal position */

    aln = node;
    do {
        len = compileLengthTree(aln.car);
        if (aln.cdr != null) {
            addOpcodeRelAddr(OPCode.PUSH, len + OPSize.JUMP);
        }
        compileTree(aln.car);
        if (aln.cdr != null) {
            len = pos - (codeLength + OPSize.JUMP);
            addOpcodeRelAddr(OPCode.JUMP, len);
        }
    } while ((aln = aln.cdr) != null);
}
 
Example 4
Source File: ArrayCompiler.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private int compileLengthEncloseNode(final EncloseNode node) {
    if (node.isOption()) {
        return compileLengthOptionNode(node);
    }

    int tlen;
    if (node.target != null) {
        tlen = compileLengthTree(node.target);
    } else {
        tlen = 0;
    }

    int len;
    switch (node.type) {
    case EncloseType.MEMORY:
        if (bsAt(regex.btMemStart, node.regNum)) {
            len = OPSize.MEMORY_START_PUSH;
        } else {
            len = OPSize.MEMORY_START;
        }
        len += tlen + (bsAt(regex.btMemEnd, node.regNum) ? OPSize.MEMORY_END_PUSH : OPSize.MEMORY_END);
        break;

    case EncloseType.STOP_BACKTRACK:
        if (node.isStopBtSimpleRepeat()) {
            final QuantifierNode qn = (QuantifierNode)node.target;
            tlen = compileLengthTree(qn.target);
            len = tlen * qn.lower + OPSize.PUSH + tlen + OPSize.POP + OPSize.JUMP;
        } else {
            len = OPSize.PUSH_STOP_BT + tlen + OPSize.POP_STOP_BT;
        }
        break;

    default:
        newInternalException(ERR_PARSER_BUG);
        return 0; // not reached
    } // switch
    return len;
}
 
Example 5
Source File: ArrayCompiler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private int compileLengthEncloseNode(final EncloseNode node) {
    if (node.isOption()) {
        return compileLengthOptionNode(node);
    }

    int tlen;
    if (node.target != null) {
        tlen = compileLengthTree(node.target);
    } else {
        tlen = 0;
    }

    int len;
    switch (node.type) {
    case EncloseType.MEMORY:
        if (bsAt(regex.btMemStart, node.regNum)) {
            len = OPSize.MEMORY_START_PUSH;
        } else {
            len = OPSize.MEMORY_START;
        }
        len += tlen + (bsAt(regex.btMemEnd, node.regNum) ? OPSize.MEMORY_END_PUSH : OPSize.MEMORY_END);
        break;

    case EncloseType.STOP_BACKTRACK:
        if (node.isStopBtSimpleRepeat()) {
            final QuantifierNode qn = (QuantifierNode)node.target;
            tlen = compileLengthTree(qn.target);
            len = tlen * qn.lower + OPSize.PUSH + tlen + OPSize.POP + OPSize.JUMP;
        } else {
            len = OPSize.PUSH_STOP_BT + tlen + OPSize.POP_STOP_BT;
        }
        break;

    default:
        newInternalException(ERR_PARSER_BUG);
        return 0; // not reached
    } // switch
    return len;
}
 
Example 6
Source File: ArrayCompiler.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private int compileLengthEncloseNode(final EncloseNode node) {
    if (node.isOption()) {
        return compileLengthOptionNode(node);
    }

    int tlen;
    if (node.target != null) {
        tlen = compileLengthTree(node.target);
    } else {
        tlen = 0;
    }

    int len;
    switch (node.type) {
    case EncloseType.MEMORY:
        if (bsAt(regex.btMemStart, node.regNum)) {
            len = OPSize.MEMORY_START_PUSH;
        } else {
            len = OPSize.MEMORY_START;
        }
        len += tlen + (bsAt(regex.btMemEnd, node.regNum) ? OPSize.MEMORY_END_PUSH : OPSize.MEMORY_END);
        break;

    case EncloseType.STOP_BACKTRACK:
        if (node.isStopBtSimpleRepeat()) {
            final QuantifierNode qn = (QuantifierNode)node.target;
            tlen = compileLengthTree(qn.target);
            len = tlen * qn.lower + OPSize.PUSH + tlen + OPSize.POP + OPSize.JUMP;
        } else {
            len = OPSize.PUSH_STOP_BT + tlen + OPSize.POP_STOP_BT;
        }
        break;

    default:
        newInternalException(ERR_PARSER_BUG);
        return 0; // not reached
    } // switch
    return len;
}
 
Example 7
Source File: ArrayCompiler.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void compileAltNode(ConsAltNode node) {
    ConsAltNode aln = node;
    int len = 0;

    do {
        len += compileLengthTree(aln.car);
        if (aln.cdr != null) {
            len += OPSize.PUSH + OPSize.JUMP;
        }
    } while ((aln = aln.cdr) != null);

    int pos = codeLength + len;  /* goal position */

    aln = node;
    do {
        len = compileLengthTree(aln.car);
        if (aln.cdr != null) {
            addOpcodeRelAddr(OPCode.PUSH, len + OPSize.JUMP);
        }
        compileTree(aln.car);
        if (aln.cdr != null) {
            len = pos - (codeLength + OPSize.JUMP);
            addOpcodeRelAddr(OPCode.JUMP, len);
        }
    } while ((aln = aln.cdr) != null);
}
 
Example 8
Source File: ArrayCompiler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void compileAltNode(final ConsAltNode node) {
    ConsAltNode aln = node;
    int len = 0;

    do {
        len += compileLengthTree(aln.car);
        if (aln.cdr != null) {
            len += OPSize.PUSH + OPSize.JUMP;
        }
    } while ((aln = aln.cdr) != null);

    final int pos = codeLength + len;  /* goal position */

    aln = node;
    do {
        len = compileLengthTree(aln.car);
        if (aln.cdr != null) {
            addOpcodeRelAddr(OPCode.PUSH, len + OPSize.JUMP);
        }
        compileTree(aln.car);
        if (aln.cdr != null) {
            len = pos - (codeLength + OPSize.JUMP);
            addOpcodeRelAddr(OPCode.JUMP, len);
        }
    } while ((aln = aln.cdr) != null);
}
 
Example 9
Source File: ArrayCompiler.java    From openjdk-jdk9 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;
}
 
Example 10
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 11
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 12
Source File: ArrayCompiler.java    From openjdk-jdk8u-backup 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;
}
 
Example 13
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 14
Source File: ArrayCompiler.java    From openjdk-jdk8u 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;
}
 
Example 15
Source File: ArrayCompiler.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
private int compileNonCECLengthQuantifierNode(final QuantifierNode qn) {
    final boolean infinite = isRepeatInfinite(qn.upper);
    final int emptyInfo = qn.targetEmptyInfo;

    final 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;
            }
            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 16
Source File: ArrayCompiler.java    From jdk8u60 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;
}
 
Example 17
Source File: ArrayCompiler.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private int compileNonCECLengthQuantifierNode(final QuantifierNode qn) {
    final boolean infinite = isRepeatInfinite(qn.upper);
    final int emptyInfo = qn.targetEmptyInfo;

    final 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;
            }
            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 18
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 19
Source File: ArrayCompiler.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private int compileNonCECLengthQuantifierNode(final QuantifierNode qn) {
    final boolean infinite = isRepeatInfinite(qn.upper);
    final int emptyInfo = qn.targetEmptyInfo;

    final 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;
            }
            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 20
Source File: ArrayCompiler.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private int compileNonCECLengthQuantifierNode(final QuantifierNode qn) {
    final boolean infinite = isRepeatInfinite(qn.upper);
    final int emptyInfo = qn.targetEmptyInfo;

    final 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;
            }
            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;
}