Wed, 20 Aug 2014 10:25:28 +0200
8044638: Tidy up Nashorn codebase for code standards
8055199: Tidy up Nashorn codebase for code standards (August 2014)
Reviewed-by: lagergren, sundar
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 */
20 package jdk.nashorn.internal.runtime.regexp.joni.ast;
22 import jdk.nashorn.internal.runtime.regexp.joni.Option;
23 import jdk.nashorn.internal.runtime.regexp.joni.constants.EncloseType;
25 public final class EncloseNode extends StateNode implements EncloseType {
27 public final int type; // enclose type
28 public int regNum;
29 public int option;
30 public Node target; /* EncloseNode : ENCLOSE_MEMORY */
31 public int callAddr; // AbsAddrType
32 public int minLength; // OnigDistance
33 public int maxLength; // OnigDistance
34 public int charLength;
35 public int optCount; // referenced count in optimize_node_left()
37 // node_new_enclose / onig_node_new_enclose
38 public EncloseNode(final int type) {
39 this.type = type;
40 callAddr = -1;
41 }
43 // node_new_enclose_memory
44 public EncloseNode() {
45 this(MEMORY);
46 }
48 // node_new_option
49 public EncloseNode(final int option, final int i) {
50 this(OPTION);
51 this.option = option;
52 }
54 @Override
55 public int getType() {
56 return ENCLOSE;
57 }
59 @Override
60 protected void setChild(final Node newChild) {
61 target = newChild;
62 }
64 @Override
65 protected Node getChild() {
66 return target;
67 }
69 public void setTarget(final Node tgt) {
70 target = tgt;
71 tgt.parent = this;
72 }
74 @Override
75 public String getName() {
76 return "Enclose";
77 }
79 @Override
80 public String toString(final int level) {
81 final StringBuilder value = new StringBuilder(super.toString(level));
82 value.append("\n type: " + typeToString());
83 value.append("\n regNum: " + regNum);
84 value.append("\n option: " + Option.toString(option));
85 value.append("\n target: " + pad(target, level + 1));
86 value.append("\n callAddr: " + callAddr);
87 value.append("\n minLength: " + minLength);
88 value.append("\n maxLength: " + maxLength);
89 value.append("\n charLength: " + charLength);
90 value.append("\n optCount: " + optCount);
92 return value.toString();
93 }
95 public String typeToString() {
96 final StringBuilder types = new StringBuilder();
97 if (isStopBacktrack()) types.append("STOP_BACKTRACK ");
98 if (isMemory()) types.append("MEMORY ");
99 if (isOption()) types.append("OPTION ");
101 return types.toString();
102 }
104 public boolean isMemory() {
105 return (type & MEMORY) != 0;
106 }
108 public boolean isOption() {
109 return (type & OPTION) != 0;
110 }
112 public boolean isStopBacktrack() {
113 return (type & STOP_BACKTRACK) != 0;
114 }
116 }