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;
  21 
  22 import jdk.nashorn.internal.runtime.regexp.joni.ScanEnvironment;
  23 
  24 @SuppressWarnings("javadoc")
  25 public final class BackRefNode extends StateNode {
  26     public final int backRef;
  27 
  28     public BackRefNode(final int backRef, final ScanEnvironment env) {
  29         this.backRef = backRef;
  30 
  31         if (backRef <= env.numMem && env.memNodes[backRef] == null) {
  32             setRecursion(); /* /...(\1).../ */
  33         }
  34     }
  35 
  36     @Override
  37     public int getType() {
  38         return BREF;
  39     }
  40 
  41     @Override
  42     public String getName() {
  43         return "Back Ref";
  44     }
  45 
  46     @Override
  47     public String toString(final int level) {
  48         final StringBuilder value = new StringBuilder(super.toString(level));
  49         value.append("\n  back: ").append(backRef);
  50         return value.toString();
  51     }
  52 }