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.joni.ast;
  21 
  22 import java.util.Set;
  23 
  24 import jdk.nashorn.internal.joni.UnsetAddrList;
  25 import jdk.nashorn.internal.joni.WarnCallback;
  26 
  27 public final class CallNode extends StateNode {
  28     public char[] name;
  29     public int nameP;
  30     public int nameEnd;
  31 
  32     public int groupNum;
  33     public Node target;             // is it an EncloseNode always ?
  34     public UnsetAddrList unsetAddrList;
  35 
  36     public CallNode(char[] name, int nameP, int nameEnd, int gnum) {
  37         this.name = name;
  38         this.nameP = nameP;
  39         this.nameEnd = nameEnd;
  40         this.groupNum = gnum; /* call by number if gnum != 0 */
  41     }
  42 
  43     @Override
  44     public int getType() {
  45         return CALL;
  46     }
  47 
  48     @Override
  49     protected void setChild(Node newChild) {
  50         target = newChild;
  51     }
  52 
  53     @Override
  54     protected Node getChild() {
  55         return target;
  56     }
  57 
  58     public void setTarget(Node tgt) {
  59         target = tgt;
  60         tgt.parent = this;
  61     }
  62 
  63     @Override
  64     public String getName() {
  65         return "Call";
  66     }
  67 
  68     @Override
  69     public void verifyTree(Set<Node> set, WarnCallback warnings) {
  70         if (target == null || target.parent == this)
  71             warnings.warn(this.getAddressName() + " doesn't point to a target or the target has been stolen");
  72         // do not recurse here
  73     }
  74 
  75     @Override
  76     public String toString(int level) {
  77         StringBuilder value = new StringBuilder(super.toString(level));
  78         value.append("\n  name: " + new String(name, nameP, nameEnd - nameP));
  79         value.append("\n  groupNum: " + groupNum);
  80         value.append("\n  target: " + pad(target.getAddressName(), level + 1));
  81         value.append("\n  unsetAddrList: " + pad(unsetAddrList, level + 1));
  82 
  83         return value.toString();
  84     }
  85 
  86 }