BackRefNode.java revision 953:221a84ef44c0
126240Swpaul/*
226240Swpaul * Permission is hereby granted, free of charge, to any person obtaining a copy of
350477Speter * this software and associated documentation files (the "Software"), to deal in
426240Swpaul * the Software without restriction, including without limitation the rights to
530908Scharnier * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
630908Scharnier * of the Software, and to permit persons to whom the Software is furnished to do
770022Sru * so, subject to the following conditions:
830908Scharnier *
930908Scharnier * The above copyright notice and this permission notice shall be included in all
1030908Scharnier * copies or substantial portions of the Software.
1130908Scharnier *
1268963Sru * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1330908Scharnier * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1495083Scharnier * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1595083Scharnier * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1695083Scharnier * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1726240Swpaul * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1826240Swpaul * SOFTWARE.
1930908Scharnier */
2026240Swpaulpackage jdk.nashorn.internal.runtime.regexp.joni.ast;
2130908Scharnier
2230908Scharnierimport jdk.nashorn.internal.runtime.regexp.joni.ScanEnvironment;
2330908Scharnier
2430908Scharnierpublic final class BackRefNode extends StateNode {
2530908Scharnier    public final int backRef;
26
27    public BackRefNode(final int backRef, final ScanEnvironment env) {
28        this.backRef = backRef;
29
30        if (backRef <= env.numMem && env.memNodes[backRef] == null) {
31            setRecursion(); /* /...(\1).../ */
32        }
33    }
34
35    @Override
36    public int getType() {
37        return BREF;
38    }
39
40    @Override
41    public String getName() {
42        return "Back Ref";
43    }
44
45    @Override
46    public String toString(final int level) {
47        final StringBuilder value = new StringBuilder(super.toString(level));
48        value.append("\n  back: ").append(backRef);
49        return value.toString();
50    }
51}
52