diff options
Diffstat (limited to 'src/jdk/nashorn/internal/runtime/regexp/joni/ast/CClassNode.java')
-rw-r--r-- | src/jdk/nashorn/internal/runtime/regexp/joni/ast/CClassNode.java | 169 |
1 files changed, 106 insertions, 63 deletions
diff --git a/src/jdk/nashorn/internal/runtime/regexp/joni/ast/CClassNode.java b/src/jdk/nashorn/internal/runtime/regexp/joni/ast/CClassNode.java index b33eeee0..bcf7aa07 100644 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/ast/CClassNode.java +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/ast/CClassNode.java @@ -19,7 +19,12 @@ */ package jdk.nashorn.internal.runtime.regexp.joni.ast; -import jdk.nashorn.internal.runtime.regexp.joni.*; +import jdk.nashorn.internal.runtime.regexp.joni.BitSet; +import jdk.nashorn.internal.runtime.regexp.joni.CodeRangeBuffer; +import jdk.nashorn.internal.runtime.regexp.joni.Config; +import jdk.nashorn.internal.runtime.regexp.joni.EncodingHelper; +import jdk.nashorn.internal.runtime.regexp.joni.ScanEnvironment; +import jdk.nashorn.internal.runtime.regexp.joni.Syntax; import jdk.nashorn.internal.runtime.regexp.joni.constants.CCSTATE; import jdk.nashorn.internal.runtime.regexp.joni.constants.CCVALTYPE; import jdk.nashorn.internal.runtime.regexp.joni.encoding.CharacterType; @@ -29,6 +34,7 @@ import jdk.nashorn.internal.runtime.regexp.joni.exception.InternalException; import jdk.nashorn.internal.runtime.regexp.joni.exception.SyntaxException; import jdk.nashorn.internal.runtime.regexp.joni.exception.ValueException; +@SuppressWarnings("javadoc") public final class CClassNode extends Node { private static final int FLAG_NCCLASS_NOT = 1<<0; private static final int FLAG_NCCLASS_SHARE = 1<<1; @@ -94,9 +100,11 @@ public final class CClassNode extends Node { } @Override - public boolean equals(Object other) { - if (!(other instanceof CClassNode)) return false; - CClassNode cc = (CClassNode)other; + public boolean equals(final Object other) { + if (!(other instanceof CClassNode)) { + return false; + } + final CClassNode cc = (CClassNode)other; return ctype == cc.ctype && isNot() == cc.isNot(); } @@ -105,16 +113,17 @@ public final class CClassNode extends Node { if (Config.USE_SHARED_CCLASS_TABLE) { int hash = 0; hash += ctype; - if (isNot()) hash++; + if (isNot()) { + hash++; + } return hash + (hash >> 5); - } else { - return super.hashCode(); } + return super.hashCode(); } @Override - public String toString(int level) { - StringBuilder value = new StringBuilder(); + public String toString(final int level) { + final StringBuilder value = new StringBuilder(); value.append("\n flags: " + flagsToString()); value.append("\n bs: " + pad(bs, level + 1)); value.append("\n mbuf: " + pad(mbuf, level + 1)); @@ -123,21 +132,25 @@ public final class CClassNode extends Node { } public String flagsToString() { - StringBuilder flags = new StringBuilder(); - if (isNot()) flags.append("NOT "); - if (isShare()) flags.append("SHARE "); - return flags.toString(); + final StringBuilder f = new StringBuilder(); + if (isNot()) { + f.append("NOT "); + } + if (isShare()) { + f.append("SHARE "); + } + return f.toString(); } public boolean isEmpty() { return mbuf == null && bs.isEmpty(); } - public void addCodeRangeToBuf(int from, int to) { + public void addCodeRangeToBuf(final int from, final int to) { mbuf = CodeRangeBuffer.addCodeRangeToBuff(mbuf, from, to); } - public void addCodeRange(ScanEnvironment env, int from, int to) { + public void addCodeRange(final ScanEnvironment env, final int from, final int to) { mbuf = CodeRangeBuffer.addCodeRange(mbuf, env, from, to); } @@ -155,22 +168,22 @@ public final class CClassNode extends Node { } // and_cclass - public void and(CClassNode other) { - boolean not1 = isNot(); + public void and(final CClassNode other) { + final boolean not1 = isNot(); BitSet bsr1 = bs; - CodeRangeBuffer buf1 = mbuf; - boolean not2 = other.isNot(); + final CodeRangeBuffer buf1 = mbuf; + final boolean not2 = other.isNot(); BitSet bsr2 = other.bs; - CodeRangeBuffer buf2 = other.mbuf; + final CodeRangeBuffer buf2 = other.mbuf; if (not1) { - BitSet bs1 = new BitSet(); + final BitSet bs1 = new BitSet(); bsr1.invertTo(bs1); bsr1 = bs1; } if (not2) { - BitSet bs2 = new BitSet(); + final BitSet bs2 = new BitSet(); bsr2.invertTo(bs2); bsr2 = bs2; } @@ -202,22 +215,22 @@ public final class CClassNode extends Node { } // or_cclass - public void or(CClassNode other) { - boolean not1 = isNot(); + public void or(final CClassNode other) { + final boolean not1 = isNot(); BitSet bsr1 = bs; - CodeRangeBuffer buf1 = mbuf; - boolean not2 = other.isNot(); + final CodeRangeBuffer buf1 = mbuf; + final boolean not2 = other.isNot(); BitSet bsr2 = other.bs; - CodeRangeBuffer buf2 = other.mbuf; + final CodeRangeBuffer buf2 = other.mbuf; if (not1) { - BitSet bs1 = new BitSet(); + final BitSet bs1 = new BitSet(); bsr1.invertTo(bs1); bsr1 = bs1; } if (not2) { - BitSet bs2 = new BitSet(); + final BitSet bs2 = new BitSet(); bsr2.invertTo(bs2); bsr2 = bs2; } @@ -246,8 +259,8 @@ public final class CClassNode extends Node { } // add_ctype_to_cc_by_range // Encoding out! - public void addCTypeByRange(int ctype, boolean not, int sbOut, int mbr[]) { - int n = mbr[0]; + 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++) { @@ -289,10 +302,14 @@ public final class CClassNode extends Node { // !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); + 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); + if (prev < 0x7fffffff/*!!!*/) { + addCodeRangeToBuf(prev, 0x7fffffff); + } return; } bs.set(j); @@ -307,22 +324,27 @@ public final class CClassNode extends Node { // !sb_end2:! prev = sbOut; for (int i=0; i<n; i++) { - if (prev < mbr[2 * i + 1]) addCodeRangeToBuf(prev, mbr[i * 2 + 1] - 1); + 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); + if (prev < 0x7fffffff/*!!!*/) { + addCodeRangeToBuf(prev, 0x7fffffff); + } } } - public void addCType(int ctype, boolean not, ScanEnvironment env, IntHolder sbOut) { + public void addCType(final int ctp, final boolean not, final ScanEnvironment env, final IntHolder sbOut) { + int ct = ctp; if (Config.NON_UNICODE_SDW) { - switch(ctype) { + switch (ct) { case CharacterType.D: case CharacterType.S: case CharacterType.W: - ctype ^= CharacterType.SPECIAL_MASK; + ct ^= CharacterType.SPECIAL_MASK; - if (env.syntax == Syntax.JAVASCRIPT && ctype == CharacterType.SPACE) { + if (env.syntax == Syntax.JAVASCRIPT && ct == CharacterType.SPACE) { // \s in JavaScript includes unicode characters. break; } @@ -330,26 +352,32 @@ public final class CClassNode extends Node { if (not) { for (int c = 0; c < BitSet.SINGLE_BYTE_SIZE; c++) { // if (!ASCIIEncoding.INSTANCE.isCodeCType(c, ctype)) bs.set(c); - if ((AsciiCtypeTable[c] & (1 << ctype)) == 0) bs.set(c); + if ((AsciiCtypeTable[c] & (1 << ct)) == 0) { + bs.set(c); + } } addAllMultiByteRange(); } else { for (int c = 0; c < BitSet.SINGLE_BYTE_SIZE; c++) { // if (ASCIIEncoding.INSTANCE.isCodeCType(c, ctype)) bs.set(c); - if ((AsciiCtypeTable[c] & (1 << ctype)) != 0) bs.set(c); + if ((AsciiCtypeTable[c] & (1 << ct)) != 0) { + bs.set(c); + } } } return; + default: + break; } } - int[] ranges = EncodingHelper.ctypeCodeRange(ctype, sbOut); + final int[] ranges = EncodingHelper.ctypeCodeRange(ct, sbOut); if (ranges != null) { - addCTypeByRange(ctype, not, sbOut.value, ranges); + addCTypeByRange(ct, not, sbOut.value, ranges); return; } - switch(ctype) { + switch(ct) { case CharacterType.ALPHA: case CharacterType.BLANK: case CharacterType.CNTRL: @@ -363,12 +391,16 @@ public final class CClassNode extends Node { case CharacterType.ALNUM: if (not) { for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) { - if (!EncodingHelper.isCodeCType(c, ctype)) bs.set(c); + if (!EncodingHelper.isCodeCType(c, ct)) { + bs.set(c); + } } addAllMultiByteRange(); } else { for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) { - if (EncodingHelper.isCodeCType(c, ctype)) bs.set(c); + if (EncodingHelper.isCodeCType(c, ct)) { + bs.set(c); + } } } break; @@ -377,11 +409,15 @@ public final class CClassNode extends Node { case CharacterType.PRINT: if (not) { for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) { - if (!EncodingHelper.isCodeCType(c, ctype)) bs.set(c); + if (!EncodingHelper.isCodeCType(c, ct)) { + bs.set(c); + } } } else { for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) { - if (EncodingHelper.isCodeCType(c, ctype)) bs.set(c); + if (EncodingHelper.isCodeCType(c, ct)) { + bs.set(c); + } } addAllMultiByteRange(); } @@ -390,13 +426,17 @@ public final class CClassNode extends Node { case CharacterType.WORD: if (!not) { for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) { - if (EncodingHelper.isWord(c)) bs.set(c); + if (EncodingHelper.isWord(c)) { + bs.set(c); + } } addAllMultiByteRange(); } else { for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) { - if (!EncodingHelper.isWord(c)) bs.set(c); + if (!EncodingHelper.isWord(c)) { + bs.set(c); + } } } break; @@ -416,8 +456,10 @@ public final class CClassNode extends Node { public CCSTATE state; } - public void nextStateClass(CCStateArg arg, ScanEnvironment env) { - if (arg.state == CCSTATE.RANGE) throw new SyntaxException(ErrorMessages.ERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE); + public void nextStateClass(final CCStateArg arg, final ScanEnvironment env) { + if (arg.state == CCSTATE.RANGE) { + throw new SyntaxException(ErrorMessages.ERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE); + } if (arg.state == CCSTATE.VALUE && arg.type != CCVALTYPE.CLASS) { if (arg.type == CCVALTYPE.SB) { @@ -430,12 +472,14 @@ public final class CClassNode extends Node { arg.type = CCVALTYPE.CLASS; } - public void nextStateValue(CCStateArg arg, ScanEnvironment env) { + public void nextStateValue(final CCStateArg arg, final ScanEnvironment env) { switch(arg.state) { case VALUE: if (arg.type == CCVALTYPE.SB) { - if (arg.vs > 0xff) throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE); + if (arg.vs > 0xff) { + throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE); + } bs.set(arg.vs); } else if (arg.type == CCVALTYPE.CODE_POINT) { addCodeRange(env, arg.vs, arg.vs); @@ -445,16 +489,17 @@ public final class CClassNode extends Node { case RANGE: if (arg.inType == arg.type) { if (arg.inType == CCVALTYPE.SB) { - if (arg.vs > 0xff || arg.v > 0xff) throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE); + if (arg.vs > 0xff || arg.v > 0xff) { + throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE); + } if (arg.vs > arg.v) { if (env.syntax.allowEmptyRangeInCC()) { // goto ccs_range_end arg.state = CCSTATE.COMPLETE; break; - } else { - throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS); } + throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS); } bs.setRange(arg.vs, arg.v); } else { @@ -466,9 +511,8 @@ public final class CClassNode extends Node { // goto ccs_range_end arg.state = CCSTATE.COMPLETE; break; - } else { - throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS); } + throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS); } bs.setRange(arg.vs, arg.v < 0xff ? arg.v : 0xff); addCodeRange(env, arg.vs, arg.v); @@ -493,7 +537,7 @@ public final class CClassNode extends Node { } // onig_is_code_in_cc_len - public boolean isCodeInCCLength(int code) { + public boolean isCodeInCCLength(final int code) { boolean found; if (code > 0xff) { @@ -504,13 +548,12 @@ public final class CClassNode extends Node { if (isNot()) { return !found; - } else { - return found; } + return found; } // onig_is_code_in_cc - public boolean isCodeInCC(int code) { + public boolean isCodeInCC(final int code) { return isCodeInCCLength(code); } |