StateNode.java revision 953:221a84ef44c0
1/* 2 * Permission is hereby granted, free of charge, to any person obtaining a copy of 3 * this software and associated documentation files (the "Software"), to deal in 4 * the Software without restriction, including without limitation the rights to 5 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 6 * of the Software, and to permit persons to whom the Software is furnished to do 7 * so, subject to the following conditions: 8 * 9 * The above copyright notice and this permission notice shall be included in all 10 * copies or substantial portions of the Software. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 * SOFTWARE. 19 */ 20package jdk.nashorn.internal.runtime.regexp.joni.ast; 21 22import jdk.nashorn.internal.runtime.regexp.joni.constants.NodeStatus; 23 24public abstract class StateNode extends Node implements NodeStatus { 25 protected int state; 26 27 @Override 28 public String toString(final int level) { 29 return "\n state: " + stateToString(); 30 } 31 32 public String stateToString() { 33 final StringBuilder states = new StringBuilder(); 34 if (isMinFixed()) states.append("MIN_FIXED "); 35 if (isMaxFixed()) states.append("MAX_FIXED "); 36 if (isMark1()) states.append("MARK1 "); 37 if (isMark2()) states.append("MARK2 "); 38 if (isMemBackrefed()) states.append("MEM_BACKREFED "); 39 if (isStopBtSimpleRepeat()) states.append("STOP_BT_SIMPLE_REPEAT "); 40 if (isRecursion()) states.append("RECURSION "); 41 if (isCalled()) states.append("CALLED "); 42 if (isAddrFixed()) states.append("ADDR_FIXED "); 43 if (isInRepeat()) states.append("IN_REPEAT "); 44 if (isNestLevel()) states.append("NEST_LEVEL "); 45 if (isByNumber()) states.append("BY_NUMBER "); 46 47 return states.toString(); 48 } 49 50 public boolean isMinFixed() { 51 return (state & NST_MIN_FIXED) != 0; 52 } 53 54 public void setMinFixed() { 55 state |= NST_MIN_FIXED; 56 } 57 58 public boolean isMaxFixed() { 59 return (state & NST_MAX_FIXED) != 0; 60 } 61 62 public void setMaxFixed() { 63 state |= NST_MAX_FIXED; 64 } 65 66 public boolean isCLenFixed() { 67 return (state & NST_CLEN_FIXED) != 0; 68 } 69 70 public void setCLenFixed() { 71 state |= NST_CLEN_FIXED; 72 } 73 74 public boolean isMark1() { 75 return (state & NST_MARK1) != 0; 76 } 77 78 public void setMark1() { 79 state |= NST_MARK1; 80 } 81 82 public boolean isMark2() { 83 return (state & NST_MARK2) != 0; 84 } 85 86 public void setMark2() { 87 state |= NST_MARK2; 88 } 89 90 public void clearMark2() { 91 state &= ~NST_MARK2; 92 } 93 94 public boolean isMemBackrefed() { 95 return (state & NST_MEM_BACKREFED) != 0; 96 } 97 98 public void setMemBackrefed() { 99 state |= NST_MEM_BACKREFED; 100 } 101 102 public boolean isStopBtSimpleRepeat() { 103 return (state & NST_STOP_BT_SIMPLE_REPEAT) != 0; 104 } 105 106 public void setStopBtSimpleRepeat() { 107 state |= NST_STOP_BT_SIMPLE_REPEAT; 108 } 109 110 public boolean isRecursion() { 111 return (state & NST_RECURSION) != 0; 112 } 113 114 public void setRecursion() { 115 state |= NST_RECURSION; 116 } 117 118 public boolean isCalled() { 119 return (state & NST_CALLED) != 0; 120 } 121 122 public void setCalled() { 123 state |= NST_CALLED; 124 } 125 126 public boolean isAddrFixed() { 127 return (state & NST_ADDR_FIXED) != 0; 128 } 129 130 public void setAddrFixed() { 131 state |= NST_ADDR_FIXED; 132 } 133 134 public boolean isInRepeat() { 135 return (state & NST_IN_REPEAT) != 0; 136 } 137 138 public void setInRepeat() { 139 state |= NST_IN_REPEAT; 140 } 141 142 public boolean isNestLevel() { 143 return (state & NST_NEST_LEVEL) != 0; 144 } 145 146 public void setNestLevel() { 147 state |= NST_NEST_LEVEL; 148 } 149 150 public boolean isByNumber() { 151 return (state & NST_BY_NUMBER) != 0; 152 } 153 154 public void setByNumber() { 155 state |= NST_BY_NUMBER; 156 } 157 158} 159