jlaskey@3: /* jlaskey@7: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. jlaskey@3: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jlaskey@3: * jlaskey@3: * This code is free software; you can redistribute it and/or modify it jlaskey@3: * under the terms of the GNU General Public License version 2 only, as jlaskey@3: * published by the Free Software Foundation. Oracle designates this jlaskey@3: * particular file as subject to the "Classpath" exception as provided jlaskey@3: * by Oracle in the LICENSE file that accompanied this code. jlaskey@3: * jlaskey@3: * This code is distributed in the hope that it will be useful, but WITHOUT jlaskey@3: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jlaskey@3: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jlaskey@3: * version 2 for more details (a copy is included in the LICENSE file that jlaskey@3: * accompanied this code). jlaskey@3: * jlaskey@3: * You should have received a copy of the GNU General Public License version jlaskey@3: * 2 along with this work; if not, write to the Free Software Foundation, jlaskey@3: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jlaskey@3: * jlaskey@3: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jlaskey@3: * or visit www.oracle.com if you need additional information or have any jlaskey@3: * questions. jlaskey@3: */ jlaskey@3: jlaskey@3: package jdk.nashorn.internal.ir; jlaskey@3: lagergren@16: import jdk.nashorn.internal.ir.annotations.Ignore; jlaskey@3: import jdk.nashorn.internal.ir.visitor.NodeVisitor; jlaskey@3: import jdk.nashorn.internal.runtime.Source; jlaskey@3: jlaskey@3: /** jlaskey@3: * IR representation for a labeled statement. jlaskey@3: * jlaskey@3: */ jlaskey@3: jlaskey@3: public class LabelNode extends Node { jlaskey@3: /** Label ident. */ jlaskey@3: private IdentNode label; jlaskey@3: jlaskey@3: /** Statements. */ jlaskey@3: private Block body; jlaskey@3: jlaskey@3: /** Node to break from. */ lagergren@16: @Ignore jlaskey@3: private Node breakNode; jlaskey@3: jlaskey@3: /** Node to continue. */ lagergren@16: @Ignore jlaskey@3: private Node continueNode; jlaskey@3: jlaskey@3: /** jlaskey@3: * Constructor jlaskey@3: * jlaskey@3: * @param source the source jlaskey@3: * @param token token jlaskey@3: * @param finish finish jlaskey@3: * @param label label identifier jlaskey@3: * @param body body of label node jlaskey@3: */ jlaskey@3: public LabelNode(final Source source, final long token, final int finish, final IdentNode label, final Block body) { jlaskey@3: super(source, token, finish); jlaskey@3: jlaskey@3: this.label = label; jlaskey@3: this.body = body; jlaskey@3: } jlaskey@3: jlaskey@3: private LabelNode(final LabelNode labelNode, final CopyState cs) { jlaskey@3: super(labelNode); jlaskey@3: jlaskey@3: label = (IdentNode)cs.existingOrCopy(labelNode.label); jlaskey@3: body = (Block)cs.existingOrCopy(labelNode.body); jlaskey@3: breakNode = cs.existingOrSame(labelNode.breakNode); jlaskey@3: continueNode = cs.existingOrSame(labelNode.continueNode); jlaskey@3: } jlaskey@3: jlaskey@3: @Override jlaskey@3: protected Node copy(final CopyState cs) { jlaskey@3: return new LabelNode(this, cs); jlaskey@3: } jlaskey@3: jlaskey@3: @Override jlaskey@3: public Node accept(final NodeVisitor visitor) { jlaskey@3: if (visitor.enter(this) != null) { jlaskey@3: label = (IdentNode)label.accept(visitor); jlaskey@3: body = (Block)body.accept(visitor); jlaskey@3: return visitor.leave(this); jlaskey@3: } jlaskey@3: jlaskey@3: return this; jlaskey@3: } jlaskey@3: jlaskey@3: @Override jlaskey@3: public void toString(final StringBuilder sb) { jlaskey@3: label.toString(sb); jlaskey@3: sb.append(':'); jlaskey@3: } jlaskey@3: jlaskey@3: /** jlaskey@3: * Get the body of the node jlaskey@3: * @return the body jlaskey@3: */ jlaskey@3: public Block getBody() { jlaskey@3: return body; jlaskey@3: } jlaskey@3: jlaskey@3: /** jlaskey@3: * Reset the body of the node jlaskey@3: * @param body new body jlaskey@3: */ jlaskey@3: public void setBody(final Block body) { jlaskey@3: this.body = body; jlaskey@3: } jlaskey@3: jlaskey@3: /** jlaskey@3: * Get the break node for this node jlaskey@3: * @return the break node jlaskey@3: */ jlaskey@3: public Node getBreakNode() { jlaskey@3: return breakNode; jlaskey@3: } jlaskey@3: jlaskey@3: /** jlaskey@3: * Reset the break node for this node jlaskey@3: * @param breakNode the break node jlaskey@3: */ jlaskey@3: public void setBreakNode(final Node breakNode) { hannesw@93: assert breakNode instanceof BreakableNode || breakNode instanceof Block : "Invalid break node: " + breakNode; jlaskey@3: this.breakNode = breakNode; jlaskey@3: } jlaskey@3: jlaskey@3: /** jlaskey@3: * Get the continue node for this node jlaskey@3: * @return the continue node jlaskey@3: */ jlaskey@3: public Node getContinueNode() { jlaskey@3: return continueNode; jlaskey@3: } jlaskey@3: jlaskey@3: /** jlaskey@3: * Reset the continue node for this node jlaskey@3: * @param continueNode the continue node jlaskey@3: */ jlaskey@3: public void setContinueNode(final Node continueNode) { hannesw@93: assert continueNode instanceof WhileNode : "invalid continue node: " + continueNode; jlaskey@3: this.continueNode = continueNode; jlaskey@3: } jlaskey@3: jlaskey@3: /** jlaskey@3: * Get the identifier representing the label name jlaskey@3: * @return the label jlaskey@3: */ jlaskey@3: public IdentNode getLabel() { jlaskey@3: return label; jlaskey@3: } jlaskey@3: jlaskey@3: }