jdk.nashorn.internal.runtime.regexp.joni.Config Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.regexp.joni.Config. 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: Node.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
public final boolean isInvalidQuantifier() {
    if (!Config.VANILLA) return false;

    ConsAltNode node;

    switch(getType()) {

    case ANCHOR:
        return true;

    case ENCLOSE:
        /* allow enclosed elements */
        /* return is_invalid_quantifier_target(NENCLOSE(node)->target); */
        break;

    case LIST:
        node = (ConsAltNode)this;
        do {
            if (!node.car.isInvalidQuantifier()) return false;
        } while ((node = node.cdr) != null);
        return false;

    case ALT:
        node = (ConsAltNode)this;
        do {
            if (node.car.isInvalidQuantifier()) return true;
        } while ((node = node.cdr) != null);
        break;

    default:
        break;
    }

    return false;
}
 
Example #2
Source File: CClassNode.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int hashCode() {
    if (Config.USE_SHARED_CCLASS_TABLE) {
        int hash = 0;
        hash += ctype;
        if (isNot()) {
            hash++;
        }
        return hash + (hash >> 5);
    }
    return super.hashCode();
}
 
Example #3
Source File: CClassNode.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int hashCode() {
    if (Config.USE_SHARED_CCLASS_TABLE) {
        int hash = 0;
        hash += ctype;
        if (isNot()) {
            hash++;
        }
        return hash + (hash >> 5);
    }
    return super.hashCode();
}
 
Example #4
Source File: CClassNode.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int hashCode() {
    if (Config.USE_SHARED_CCLASS_TABLE) {
        int hash = 0;
        hash += ctype;
        if (isNot()) {
            hash++;
        }
        return hash + (hash >> 5);
    }
    return super.hashCode();
}
 
Example #5
Source File: CClassNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int hashCode() {
    if (Config.USE_SHARED_CCLASS_TABLE) {
        int hash = 0;
        hash += ctype;
        if (isNot()) {
            hash++;
        }
        return hash + (hash >> 5);
    }
    return super.hashCode();
}
 
Example #6
Source File: Node.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public final boolean isInvalidQuantifier() {
    if (!Config.VANILLA) return false;

    ConsAltNode node;

    switch(getType()) {

    case ANCHOR:
        return true;

    case ENCLOSE:
        /* allow enclosed elements */
        /* return is_invalid_quantifier_target(NENCLOSE(node)->target); */
        break;

    case LIST:
        node = (ConsAltNode)this;
        do {
            if (!node.car.isInvalidQuantifier()) return false;
        } while ((node = node.cdr) != null);
        return false;

    case ALT:
        node = (ConsAltNode)this;
        do {
            if (node.car.isInvalidQuantifier()) return true;
        } while ((node = node.cdr) != null);
        break;

    default:
        break;
    }

    return false;
}
 
Example #7
Source File: Node.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public final boolean isInvalidQuantifier() {
    if (!Config.VANILLA) return false;

    ConsAltNode node;

    switch(getType()) {

    case ANCHOR:
        return true;

    case ENCLOSE:
        /* allow enclosed elements */
        /* return is_invalid_quantifier_target(NENCLOSE(node)->target); */
        break;

    case LIST:
        node = (ConsAltNode)this;
        do {
            if (!node.car.isInvalidQuantifier()) return false;
        } while ((node = node.cdr) != null);
        return false;

    case ALT:
        node = (ConsAltNode)this;
        do {
            if (node.car.isInvalidQuantifier()) return true;
        } while ((node = node.cdr) != null);
        break;

    default:
        break;
    }

    return false;
}
 
Example #8
Source File: CClassNode.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int hashCode() {
    if (Config.USE_SHARED_CCLASS_TABLE) {
        int hash = 0;
        hash += ctype;
        if (isNot()) {
            hash++;
        }
        return hash + (hash >> 5);
    }
    return super.hashCode();
}
 
Example #9
Source File: CClassNode.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int hashCode() {
    if (Config.USE_SHARED_CCLASS_TABLE) {
        int hash = 0;
        hash += ctype;
        if (isNot()) {
            hash++;
        }
        return hash + (hash >> 5);
    }
    return super.hashCode();
}
 
Example #10
Source File: CClassNode.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int hashCode() {
    if (Config.USE_SHARED_CCLASS_TABLE) {
        int hash = 0;
        hash += ctype;
        if (isNot()) {
            hash++;
        }
        return hash + (hash >> 5);
    }
    return super.hashCode();
}
 
Example #11
Source File: CClassNode.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
public void addCTypeByRange(final int ct, final boolean not, final int sbOut, final int mbr[]) {
    final int n = mbr[0];

    if (!not) {
        for (int i=0; i<n; i++) {
            for (int j=mbr[i * 2 + 1]; j<=mbr[i * 2 + 2]; j++) {
                if (j >= sbOut) {
                    if (Config.VANILLA) {
                        if (j == mbr[i * 2 + 2]) {
                            i++;
                        } else if (j > mbr[i * 2 + 1]) {
                            addCodeRangeToBuf(j, mbr[i * 2 + 2]);
                            i++;
                        }
                    } else {
                        if (j >= mbr[i * 2 + 1]) {
                            addCodeRangeToBuf(j, mbr[i * 2 + 2]);
                            i++;
                        }
                    }
                    // !goto sb_end!, remove duplication!
                    for (; i<n; i++) {
                        addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
                    }
                    return;
                }
                bs.set(j);
            }
        }
        // !sb_end:!
        for (int i=0; i<n; i++) {
            addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
        }

    } else {
        int prev = 0;

        for (int i=0; i<n; i++) {
            for (int j=prev; j < mbr[2 * i + 1]; j++) {
                if (j >= sbOut) {
                    // !goto sb_end2!, remove duplication
                    prev = sbOut;
                    for (i=0; i<n; i++) {
                        if (prev < mbr[2 * i + 1]) {
                            addCodeRangeToBuf(prev, mbr[i * 2 + 1] - 1);
                        }
                        prev = mbr[i * 2 + 2] + 1;
                    }
                    if (prev < 0x7fffffff/*!!!*/) {
                        addCodeRangeToBuf(prev, 0x7fffffff);
                    }
                    return;
                }
                bs.set(j);
            }
            prev = mbr[2 * i + 2] + 1;
        }

        for (int j=prev; j<sbOut; j++) {
            bs.set(j);
        }

        // !sb_end2:!
        prev = sbOut;
        for (int i=0; i<n; i++) {
            if (prev < mbr[2 * i + 1]) {
                addCodeRangeToBuf(prev, mbr[i * 2 + 1] - 1);
            }
            prev = mbr[i * 2 + 2] + 1;
        }
        if (prev < 0x7fffffff/*!!!*/) {
            addCodeRangeToBuf(prev, 0x7fffffff);
        }
    }
}
 
Example #12
Source File: QuantifierNode.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(Node tgt, boolean group, ScanEnvironment env, char[] chars, int p, int end) {
    if (lower == 1 && upper == 1) return 1;

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        QuantifierNode qnt = (QuantifierNode)tgt;
        int nestQNum = popularNum();
        int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #13
Source File: QuantifierNode.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(final Node tgt, final boolean group, final ScanEnvironment env, final char[] chars, final int p, final int end) {
    if (lower == 1 && upper == 1) {
        return 1;
    }

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            final StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                final StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        final QuantifierNode qnt = (QuantifierNode)tgt;
        final int nestQNum = popularNum();
        final int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #14
Source File: QuantifierNode.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(Node tgt, boolean group, ScanEnvironment env, char[] chars, int p, int end) {
    if (lower == 1 && upper == 1) return 1;

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        QuantifierNode qnt = (QuantifierNode)tgt;
        int nestQNum = popularNum();
        int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #15
Source File: Node.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public final boolean isInvalidQuantifier() {
    if (!Config.VANILLA) {
        return false;
    }

    ConsAltNode node;

    switch(getType()) {

    case ANCHOR:
        return true;

    case ENCLOSE:
        /* allow enclosed elements */
        /* return is_invalid_quantifier_target(NENCLOSE(node)->target); */
        break;

    case LIST:
        node = (ConsAltNode)this;
        do {
            if (!node.car.isInvalidQuantifier()) {
                return false;
            }
        } while ((node = node.cdr) != null);
        return false;

    case ALT:
        node = (ConsAltNode)this;
        do {
            if (node.car.isInvalidQuantifier()) {
                return true;
            }
        } while ((node = node.cdr) != null);
        break;

    default:
        break;
    }

    return false;
}
 
Example #16
Source File: QuantifierNode.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(final Node tgt, final boolean group, final ScanEnvironment env, final char[] chars, final int p, final int end) {
    if (lower == 1 && upper == 1) {
        return 1;
    }

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            final StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                final StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        final QuantifierNode qnt = (QuantifierNode)tgt;
        final int nestQNum = popularNum();
        final int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #17
Source File: Node.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
public final boolean isInvalidQuantifier() {
    if (!Config.VANILLA) {
        return false;
    }

    ConsAltNode node;

    switch(getType()) {

    case ANCHOR:
        return true;

    case ENCLOSE:
        /* allow enclosed elements */
        /* return is_invalid_quantifier_target(NENCLOSE(node)->target); */
        break;

    case LIST:
        node = (ConsAltNode)this;
        do {
            if (!node.car.isInvalidQuantifier()) {
                return false;
            }
        } while ((node = node.cdr) != null);
        return false;

    case ALT:
        node = (ConsAltNode)this;
        do {
            if (node.car.isInvalidQuantifier()) {
                return true;
            }
        } while ((node = node.cdr) != null);
        break;

    default:
        break;
    }

    return false;
}
 
Example #18
Source File: QuantifierNode.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(Node tgt, boolean group, ScanEnvironment env, char[] chars, int p, int end) {
    if (lower == 1 && upper == 1) return 1;

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        QuantifierNode qnt = (QuantifierNode)tgt;
        int nestQNum = popularNum();
        int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #19
Source File: CClassNode.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void addCTypeByRange(final int ct, final boolean not, final int sbOut, final int mbr[]) {
    final int n = mbr[0];

    if (!not) {
        for (int i=0; i<n; i++) {
            for (int j=mbr[i * 2 + 1]; j<=mbr[i * 2 + 2]; j++) {
                if (j >= sbOut) {
                    if (Config.VANILLA) {
                        if (j == mbr[i * 2 + 2]) {
                            i++;
                        } else if (j > mbr[i * 2 + 1]) {
                            addCodeRangeToBuf(j, mbr[i * 2 + 2]);
                            i++;
                        }
                    } else {
                        if (j >= mbr[i * 2 + 1]) {
                            addCodeRangeToBuf(j, mbr[i * 2 + 2]);
                            i++;
                        }
                    }
                    // !goto sb_end!, remove duplication!
                    for (; i<n; i++) {
                        addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
                    }
                    return;
                }
                bs.set(j);
            }
        }
        // !sb_end:!
        for (int i=0; i<n; i++) {
            addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
        }

    } else {
        int prev = 0;

        for (int i=0; i<n; i++) {
            for (int j=prev; j < mbr[2 * i + 1]; j++) {
                if (j >= sbOut) {
                    // !goto sb_end2!, remove duplication
                    prev = sbOut;
                    for (i=0; i<n; i++) {
                        if (prev < mbr[2 * i + 1]) {
                            addCodeRangeToBuf(prev, mbr[i * 2 + 1] - 1);
                        }
                        prev = mbr[i * 2 + 2] + 1;
                    }
                    if (prev < 0x7fffffff/*!!!*/) {
                        addCodeRangeToBuf(prev, 0x7fffffff);
                    }
                    return;
                }
                bs.set(j);
            }
            prev = mbr[2 * i + 2] + 1;
        }

        for (int j=prev; j<sbOut; j++) {
            bs.set(j);
        }

        // !sb_end2:!
        prev = sbOut;
        for (int i=0; i<n; i++) {
            if (prev < mbr[2 * i + 1]) {
                addCodeRangeToBuf(prev, mbr[i * 2 + 1] - 1);
            }
            prev = mbr[i * 2 + 2] + 1;
        }
        if (prev < 0x7fffffff/*!!!*/) {
            addCodeRangeToBuf(prev, 0x7fffffff);
        }
    }
}
 
Example #20
Source File: CClassNode.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void addCTypeByRange(final int ct, final boolean not, final int sbOut, final int mbr[]) {
    final int n = mbr[0];

    if (!not) {
        for (int i=0; i<n; i++) {
            for (int j=mbr[i * 2 + 1]; j<=mbr[i * 2 + 2]; j++) {
                if (j >= sbOut) {
                    if (Config.VANILLA) {
                        if (j == mbr[i * 2 + 2]) {
                            i++;
                        } else if (j > mbr[i * 2 + 1]) {
                            addCodeRangeToBuf(j, mbr[i * 2 + 2]);
                            i++;
                        }
                    } else {
                        if (j >= mbr[i * 2 + 1]) {
                            addCodeRangeToBuf(j, mbr[i * 2 + 2]);
                            i++;
                        }
                    }
                    // !goto sb_end!, remove duplication!
                    for (; i<n; i++) {
                        addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
                    }
                    return;
                }
                bs.set(j);
            }
        }
        // !sb_end:!
        for (int i=0; i<n; i++) {
            addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
        }

    } else {
        int prev = 0;

        for (int i=0; i<n; i++) {
            for (int j=prev; j < mbr[2 * i + 1]; j++) {
                if (j >= sbOut) {
                    // !goto sb_end2!, remove duplication
                    prev = sbOut;
                    for (i=0; i<n; i++) {
                        if (prev < mbr[2 * i + 1]) {
                            addCodeRangeToBuf(prev, mbr[i * 2 + 1] - 1);
                        }
                        prev = mbr[i * 2 + 2] + 1;
                    }
                    if (prev < 0x7fffffff/*!!!*/) {
                        addCodeRangeToBuf(prev, 0x7fffffff);
                    }
                    return;
                }
                bs.set(j);
            }
            prev = mbr[2 * i + 2] + 1;
        }

        for (int j=prev; j<sbOut; j++) {
            bs.set(j);
        }

        // !sb_end2:!
        prev = sbOut;
        for (int i=0; i<n; i++) {
            if (prev < mbr[2 * i + 1]) {
                addCodeRangeToBuf(prev, mbr[i * 2 + 1] - 1);
            }
            prev = mbr[i * 2 + 2] + 1;
        }
        if (prev < 0x7fffffff/*!!!*/) {
            addCodeRangeToBuf(prev, 0x7fffffff);
        }
    }
}
 
Example #21
Source File: Node.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public final boolean isInvalidQuantifier() {
    if (!Config.VANILLA) {
        return false;
    }

    ConsAltNode node;

    switch(getType()) {

    case ANCHOR:
        return true;

    case ENCLOSE:
        /* allow enclosed elements */
        /* return is_invalid_quantifier_target(NENCLOSE(node)->target); */
        break;

    case LIST:
        node = (ConsAltNode)this;
        do {
            if (!node.car.isInvalidQuantifier()) {
                return false;
            }
        } while ((node = node.cdr) != null);
        return false;

    case ALT:
        node = (ConsAltNode)this;
        do {
            if (node.car.isInvalidQuantifier()) {
                return true;
            }
        } while ((node = node.cdr) != null);
        break;

    default:
        break;
    }

    return false;
}
 
Example #22
Source File: QuantifierNode.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(final Node tgt, final boolean group, final ScanEnvironment env, final char[] chars, final int p, final int end) {
    if (lower == 1 && upper == 1) {
        return 1;
    }

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            final StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                final StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        final QuantifierNode qnt = (QuantifierNode)tgt;
        final int nestQNum = popularNum();
        final int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #23
Source File: Node.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public final boolean isInvalidQuantifier() {
    if (!Config.VANILLA) {
        return false;
    }

    ConsAltNode node;

    switch(getType()) {

    case ANCHOR:
        return true;

    case ENCLOSE:
        /* allow enclosed elements */
        /* return is_invalid_quantifier_target(NENCLOSE(node)->target); */
        break;

    case LIST:
        node = (ConsAltNode)this;
        do {
            if (!node.car.isInvalidQuantifier()) {
                return false;
            }
        } while ((node = node.cdr) != null);
        return false;

    case ALT:
        node = (ConsAltNode)this;
        do {
            if (node.car.isInvalidQuantifier()) {
                return true;
            }
        } while ((node = node.cdr) != null);
        break;

    default:
        break;
    }

    return false;
}
 
Example #24
Source File: QuantifierNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(final Node tgt, final boolean group, final ScanEnvironment env, final char[] chars, final int p, final int end) {
    if (lower == 1 && upper == 1) {
        return 1;
    }

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            final StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                final StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        final QuantifierNode qnt = (QuantifierNode)tgt;
        final int nestQNum = popularNum();
        final int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #25
Source File: CClassNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void addCTypeByRange(final int ct, final boolean not, final int sbOut, final int mbr[]) {
    final int n = mbr[0];

    if (!not) {
        for (int i=0; i<n; i++) {
            for (int j=mbr[i * 2 + 1]; j<=mbr[i * 2 + 2]; j++) {
                if (j >= sbOut) {
                    if (Config.VANILLA) {
                        if (j == mbr[i * 2 + 2]) {
                            i++;
                        } else if (j > mbr[i * 2 + 1]) {
                            addCodeRangeToBuf(j, mbr[i * 2 + 2]);
                            i++;
                        }
                    } else {
                        if (j >= mbr[i * 2 + 1]) {
                            addCodeRangeToBuf(j, mbr[i * 2 + 2]);
                            i++;
                        }
                    }
                    // !goto sb_end!, remove duplication!
                    for (; i<n; i++) {
                        addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
                    }
                    return;
                }
                bs.set(j);
            }
        }
        // !sb_end:!
        for (int i=0; i<n; i++) {
            addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
        }

    } else {
        int prev = 0;

        for (int i=0; i<n; i++) {
            for (int j=prev; j < mbr[2 * i + 1]; j++) {
                if (j >= sbOut) {
                    // !goto sb_end2!, remove duplication
                    prev = sbOut;
                    for (i=0; i<n; i++) {
                        if (prev < mbr[2 * i + 1]) {
                            addCodeRangeToBuf(prev, mbr[i * 2 + 1] - 1);
                        }
                        prev = mbr[i * 2 + 2] + 1;
                    }
                    if (prev < 0x7fffffff/*!!!*/) {
                        addCodeRangeToBuf(prev, 0x7fffffff);
                    }
                    return;
                }
                bs.set(j);
            }
            prev = mbr[2 * i + 2] + 1;
        }

        for (int j=prev; j<sbOut; j++) {
            bs.set(j);
        }

        // !sb_end2:!
        prev = sbOut;
        for (int i=0; i<n; i++) {
            if (prev < mbr[2 * i + 1]) {
                addCodeRangeToBuf(prev, mbr[i * 2 + 1] - 1);
            }
            prev = mbr[i * 2 + 2] + 1;
        }
        if (prev < 0x7fffffff/*!!!*/) {
            addCodeRangeToBuf(prev, 0x7fffffff);
        }
    }
}
 
Example #26
Source File: Node.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public final boolean isInvalidQuantifier() {
    if (!Config.VANILLA) {
        return false;
    }

    ConsAltNode node;

    switch(getType()) {

    case ANCHOR:
        return true;

    case ENCLOSE:
        /* allow enclosed elements */
        /* return is_invalid_quantifier_target(NENCLOSE(node)->target); */
        break;

    case LIST:
        node = (ConsAltNode)this;
        do {
            if (!node.car.isInvalidQuantifier()) {
                return false;
            }
        } while ((node = node.cdr) != null);
        return false;

    case ALT:
        node = (ConsAltNode)this;
        do {
            if (node.car.isInvalidQuantifier()) {
                return true;
            }
        } while ((node = node.cdr) != null);
        break;

    default:
        break;
    }

    return false;
}
 
Example #27
Source File: QuantifierNode.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(final Node tgt, final boolean group, final ScanEnvironment env, final char[] chars, final int p, final int end) {
    if (lower == 1 && upper == 1) {
        return 1;
    }

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            final StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                final StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        final QuantifierNode qnt = (QuantifierNode)tgt;
        final int nestQNum = popularNum();
        final int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #28
Source File: CClassNode.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void addCTypeByRange(final int ct, final boolean not, final int sbOut, final int mbr[]) {
    final int n = mbr[0];

    if (!not) {
        for (int i=0; i<n; i++) {
            for (int j=mbr[i * 2 + 1]; j<=mbr[i * 2 + 2]; j++) {
                if (j >= sbOut) {
                    if (Config.VANILLA) {
                        if (j == mbr[i * 2 + 2]) {
                            i++;
                        } else if (j > mbr[i * 2 + 1]) {
                            addCodeRangeToBuf(j, mbr[i * 2 + 2]);
                            i++;
                        }
                    } else {
                        if (j >= mbr[i * 2 + 1]) {
                            addCodeRangeToBuf(j, mbr[i * 2 + 2]);
                            i++;
                        }
                    }
                    // !goto sb_end!, remove duplication!
                    for (; i<n; i++) {
                        addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
                    }
                    return;
                }
                bs.set(j);
            }
        }
        // !sb_end:!
        for (int i=0; i<n; i++) {
            addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
        }

    } else {
        int prev = 0;

        for (int i=0; i<n; i++) {
            for (int j=prev; j < mbr[2 * i + 1]; j++) {
                if (j >= sbOut) {
                    // !goto sb_end2!, remove duplication
                    prev = sbOut;
                    for (i=0; i<n; i++) {
                        if (prev < mbr[2 * i + 1]) {
                            addCodeRangeToBuf(prev, mbr[i * 2 + 1] - 1);
                        }
                        prev = mbr[i * 2 + 2] + 1;
                    }
                    if (prev < 0x7fffffff/*!!!*/) {
                        addCodeRangeToBuf(prev, 0x7fffffff);
                    }
                    return;
                }
                bs.set(j);
            }
            prev = mbr[2 * i + 2] + 1;
        }

        for (int j=prev; j<sbOut; j++) {
            bs.set(j);
        }

        // !sb_end2:!
        prev = sbOut;
        for (int i=0; i<n; i++) {
            if (prev < mbr[2 * i + 1]) {
                addCodeRangeToBuf(prev, mbr[i * 2 + 1] - 1);
            }
            prev = mbr[i * 2 + 2] + 1;
        }
        if (prev < 0x7fffffff/*!!!*/) {
            addCodeRangeToBuf(prev, 0x7fffffff);
        }
    }
}
 
Example #29
Source File: Node.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public final boolean isInvalidQuantifier() {
    if (!Config.VANILLA) {
        return false;
    }

    ConsAltNode node;

    switch(getType()) {

    case ANCHOR:
        return true;

    case ENCLOSE:
        /* allow enclosed elements */
        /* return is_invalid_quantifier_target(NENCLOSE(node)->target); */
        break;

    case LIST:
        node = (ConsAltNode)this;
        do {
            if (!node.car.isInvalidQuantifier()) {
                return false;
            }
        } while ((node = node.cdr) != null);
        return false;

    case ALT:
        node = (ConsAltNode)this;
        do {
            if (node.car.isInvalidQuantifier()) {
                return true;
            }
        } while ((node = node.cdr) != null);
        break;

    default:
        break;
    }

    return false;
}
 
Example #30
Source File: QuantifierNode.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(final Node tgt, final boolean group, final ScanEnvironment env, final char[] chars, final int p, final int end) {
    if (lower == 1 && upper == 1) {
        return 1;
    }

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            final StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                final StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        final QuantifierNode qnt = (QuantifierNode)tgt;
        final int nestQNum = popularNum();
        final int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}