nashorn/src/jdk/nashorn/internal/ir/LabeledNode.java
changeset 18399 1bfb28b29bc6
parent 18397 bd6f6d46c14b
parent 17289 4dec41b3c5e3
child 18400 66264fd9d5dd
equal deleted inserted replaced
18397:bd6f6d46c14b 18399:1bfb28b29bc6
     1 /*
       
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package jdk.nashorn.internal.ir;
       
    27 
       
    28 import jdk.nashorn.internal.ir.annotations.Ignore;
       
    29 import jdk.nashorn.internal.runtime.Source;
       
    30 
       
    31 /**
       
    32  * IR base class for break and continue.
       
    33  *
       
    34  */
       
    35 public abstract class LabeledNode extends Node {
       
    36     /** Optional label. */
       
    37     @Ignore
       
    38     protected final LabelNode labelNode;
       
    39 
       
    40     /** Target control node. */
       
    41     @Ignore
       
    42     protected final Node targetNode;
       
    43 
       
    44     /** Try chain. */
       
    45     @Ignore
       
    46     protected final TryNode tryChain;
       
    47 
       
    48     /** scope nesting level */
       
    49     protected int scopeNestingLevel;
       
    50 
       
    51     /**
       
    52      * Constructor
       
    53      *
       
    54      * @param source     the source
       
    55      * @param token      token
       
    56      * @param finish     finish
       
    57      * @param labelNode  the label node
       
    58      * @param targetNode the place to break to
       
    59      * @param tryChain   the try chain
       
    60      */
       
    61     public LabeledNode(final Source source, final long token, final int finish, final LabelNode labelNode, final Node targetNode, final TryNode tryChain) {
       
    62         super(source, token, finish);
       
    63 
       
    64         this.labelNode  = labelNode;
       
    65         this.targetNode = targetNode;
       
    66         this.tryChain   = tryChain;
       
    67     }
       
    68 
       
    69     /**
       
    70      * Copy constructor
       
    71      *
       
    72      * @param labeledNode source node
       
    73      * @param cs          copy state
       
    74      */
       
    75     protected LabeledNode(final LabeledNode labeledNode, final CopyState cs) {
       
    76         super(labeledNode);
       
    77 
       
    78         this.labelNode         = (LabelNode)cs.existingOrCopy(labeledNode.labelNode);
       
    79         this.targetNode        = cs.existingOrSame(labeledNode.targetNode);
       
    80         this.tryChain          = (TryNode)cs.existingOrSame(labeledNode.tryChain);
       
    81         this.scopeNestingLevel = labeledNode.scopeNestingLevel;
       
    82     }
       
    83 
       
    84     /**
       
    85      * Get the label
       
    86      * @return the label
       
    87      */
       
    88     public LabelNode getLabel() {
       
    89         return labelNode;
       
    90     }
       
    91 
       
    92     /**
       
    93      * Get the target node
       
    94      * @return the target node
       
    95      */
       
    96     public Node getTargetNode() {
       
    97         return targetNode;
       
    98     }
       
    99 
       
   100     /**
       
   101      * Get the surrounding try chain
       
   102      * @return the try chain
       
   103      */
       
   104     public TryNode getTryChain() {
       
   105         return tryChain;
       
   106     }
       
   107 
       
   108     /**
       
   109      * Get the scope nesting level
       
   110      * @return nesting level
       
   111      */
       
   112     public int getScopeNestingLevel() {
       
   113         return scopeNestingLevel;
       
   114     }
       
   115 
       
   116     /**
       
   117      * Set scope nesting level
       
   118      * @param level the new level
       
   119      */
       
   120     public void setScopeNestingLevel(final int level) {
       
   121         scopeNestingLevel = level;
       
   122     }
       
   123 }