nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/ast/Node.java
changeset 27361 86c4ddb4797b
parent 25865 d38d876f1654
child 31549 b627094c5649
equal deleted inserted replaced
27360:a19c14022fa4 27361:86c4ddb4797b
    22 import java.util.Set;
    22 import java.util.Set;
    23 import jdk.nashorn.internal.runtime.regexp.joni.Config;
    23 import jdk.nashorn.internal.runtime.regexp.joni.Config;
    24 import jdk.nashorn.internal.runtime.regexp.joni.WarnCallback;
    24 import jdk.nashorn.internal.runtime.regexp.joni.WarnCallback;
    25 import jdk.nashorn.internal.runtime.regexp.joni.constants.NodeType;
    25 import jdk.nashorn.internal.runtime.regexp.joni.constants.NodeType;
    26 
    26 
       
    27 @SuppressWarnings("javadoc")
    27 public abstract class Node implements NodeType {
    28 public abstract class Node implements NodeType {
    28     public Node parent;
    29     public Node parent;
    29 
    30 
    30     public abstract int getType();
    31     public abstract int getType();
    31 
    32 
    32     public final int getType2Bit() {
    33     public final int getType2Bit() {
    33         return 1 << getType();
    34         return 1 << getType();
    34     }
    35     }
    35 
    36 
    36     protected void setChild(final Node tgt){}         // default definition
    37     protected void setChild(final Node tgt) {
    37     protected Node getChild(){return null;}     // default definition
    38         //empty, default definition
       
    39     }
       
    40     protected Node getChild() {
       
    41         return null; // default definition
       
    42         }
    38 
    43 
    39     public void swap(final Node with) {
    44     public void swap(final Node with) {
    40         Node tmp;
    45         Node tmp;
    41 
    46 
    42         //if (getChild() != null) getChild().parent = with;
    47         //if (getChild() != null) getChild().parent = with;
    44 
    49 
    45         //tmp = getChild();
    50         //tmp = getChild();
    46         //setChild(with.getChild());
    51         //setChild(with.getChild());
    47         //with.setChild(tmp);
    52         //with.setChild(tmp);
    48 
    53 
    49         if (parent != null) parent.setChild(with);
    54         if (parent != null) {
       
    55             parent.setChild(with);
       
    56         }
    50 
    57 
    51         if (with.parent != null) with.parent.setChild(this);
    58         if (with.parent != null) {
       
    59             with.parent.setChild(this);
       
    60         }
    52 
    61 
    53         tmp = parent;
    62         tmp = parent;
    54         parent = with.parent;
    63         parent = with.parent;
    55         with.parent = tmp;
    64         with.parent = tmp;
    56     }
    65     }
    79         s.append("<" + getAddressName() + " (" + (parent == null ? "NULL" : parent.getAddressName())  + ")>");
    88         s.append("<" + getAddressName() + " (" + (parent == null ? "NULL" : parent.getAddressName())  + ")>");
    80         return s + toString(0);
    89         return s + toString(0);
    81     }
    90     }
    82 
    91 
    83     protected static String pad(final Object value, final int level) {
    92     protected static String pad(final Object value, final int level) {
    84         if (value == null) return "NULL";
    93         if (value == null) {
       
    94             return "NULL";
       
    95         }
    85 
    96 
    86         final StringBuilder pad = new StringBuilder("  ");
    97         final StringBuilder pad = new StringBuilder("  ");
    87         for (int i=0; i<level; i++) pad.append(pad);
    98         for (int i=0; i<level; i++) {
       
    99             pad.append(pad);
       
   100         }
    88 
   101 
    89         return value.toString().replace("\n",  "\n" + pad);
   102         return value.toString().replace("\n",  "\n" + pad);
    90     }
   103     }
    91 
   104 
    92     public final boolean isInvalidQuantifier() {
   105     public final boolean isInvalidQuantifier() {
    93         if (!Config.VANILLA) return false;
   106         if (!Config.VANILLA) {
       
   107             return false;
       
   108         }
    94 
   109 
    95         ConsAltNode node;
   110         ConsAltNode node;
    96 
   111 
    97         switch(getType()) {
   112         switch(getType()) {
    98 
   113 
   105             break;
   120             break;
   106 
   121 
   107         case LIST:
   122         case LIST:
   108             node = (ConsAltNode)this;
   123             node = (ConsAltNode)this;
   109             do {
   124             do {
   110                 if (!node.car.isInvalidQuantifier()) return false;
   125                 if (!node.car.isInvalidQuantifier()) {
       
   126                     return false;
       
   127                 }
   111             } while ((node = node.cdr) != null);
   128             } while ((node = node.cdr) != null);
   112             return false;
   129             return false;
   113 
   130 
   114         case ALT:
   131         case ALT:
   115             node = (ConsAltNode)this;
   132             node = (ConsAltNode)this;
   116             do {
   133             do {
   117                 if (node.car.isInvalidQuantifier()) return true;
   134                 if (node.car.isInvalidQuantifier()) {
       
   135                     return true;
       
   136                 }
   118             } while ((node = node.cdr) != null);
   137             } while ((node = node.cdr) != null);
   119             break;
   138             break;
   120 
   139 
   121         default:
   140         default:
   122             break;
   141             break;