src/jdk/nashorn/internal/ir/ThrowNode.java

Fri, 15 Feb 2013 09:44:15 +0100

author
lagergren
date
Fri, 15 Feb 2013 09:44:15 +0100
changeset 96
e478708faa22
parent 16
69a4f0363d0f
child 144
4be452026847
permissions
-rw-r--r--

8008239: Unpublicized parts of the code generator package that were only package internal.
Reviewed-by: hannesw, attila

jlaskey@3 1 /*
jlaskey@7 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
jlaskey@3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jlaskey@3 4 *
jlaskey@3 5 * This code is free software; you can redistribute it and/or modify it
jlaskey@3 6 * under the terms of the GNU General Public License version 2 only, as
jlaskey@3 7 * published by the Free Software Foundation. Oracle designates this
jlaskey@3 8 * particular file as subject to the "Classpath" exception as provided
jlaskey@3 9 * by Oracle in the LICENSE file that accompanied this code.
jlaskey@3 10 *
jlaskey@3 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jlaskey@3 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jlaskey@3 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jlaskey@3 14 * version 2 for more details (a copy is included in the LICENSE file that
jlaskey@3 15 * accompanied this code).
jlaskey@3 16 *
jlaskey@3 17 * You should have received a copy of the GNU General Public License version
jlaskey@3 18 * 2 along with this work; if not, write to the Free Software Foundation,
jlaskey@3 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jlaskey@3 20 *
jlaskey@3 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jlaskey@3 22 * or visit www.oracle.com if you need additional information or have any
jlaskey@3 23 * questions.
jlaskey@3 24 */
jlaskey@3 25
jlaskey@3 26 package jdk.nashorn.internal.ir;
jlaskey@3 27
jlaskey@3 28 import jdk.nashorn.internal.ir.annotations.Ignore;
jlaskey@3 29 import jdk.nashorn.internal.ir.visitor.NodeVisitor;
jlaskey@3 30 import jdk.nashorn.internal.runtime.Source;
jlaskey@3 31
jlaskey@3 32 /**
jlaskey@3 33 * IR representation for THROW statements.
jlaskey@3 34 */
jlaskey@3 35 public class ThrowNode extends Node {
jlaskey@3 36 /** Exception expression. */
jlaskey@3 37 private Node expression;
jlaskey@3 38
jlaskey@3 39 /** Try chain. */
lagergren@16 40 @Ignore
jlaskey@3 41 private final TryNode tryChain;
jlaskey@3 42
jlaskey@3 43 /**
jlaskey@3 44 * Constructor
jlaskey@3 45 *
jlaskey@3 46 * @param source the source
jlaskey@3 47 * @param token token
jlaskey@3 48 * @param finish finish
jlaskey@3 49 * @param expression expression to throw
jlaskey@3 50 * @param tryChain surrounding try chain
jlaskey@3 51 */
jlaskey@3 52 public ThrowNode(final Source source, final long token, final int finish, final Node expression, final TryNode tryChain) {
jlaskey@3 53 super(source, token, finish);
jlaskey@3 54
jlaskey@3 55 this.expression = expression;
jlaskey@3 56 this.tryChain = tryChain;
jlaskey@3 57 setIsTerminal(true);
jlaskey@3 58 }
jlaskey@3 59
jlaskey@3 60 private ThrowNode(final ThrowNode throwNode, final CopyState cs) {
jlaskey@3 61 super(throwNode);
jlaskey@3 62
lagergren@96 63 this.expression = cs.existingOrCopy(throwNode.expression);
lagergren@96 64 this.tryChain = (TryNode)cs.existingOrSame(throwNode.tryChain);
jlaskey@3 65 }
jlaskey@3 66
jlaskey@3 67 @Override
jlaskey@3 68 protected Node copy(final CopyState cs) {
jlaskey@3 69 return new ThrowNode(this, cs);
jlaskey@3 70 }
jlaskey@3 71
jlaskey@3 72 /**
jlaskey@3 73 * Assist in IR navigation.
jlaskey@3 74 * @param visitor IR navigating visitor.
jlaskey@3 75 */
jlaskey@3 76 @Override
jlaskey@3 77 public Node accept(final NodeVisitor visitor) {
jlaskey@3 78 if (visitor.enter(this) != null) {
jlaskey@3 79 setExpression(expression.accept(visitor));
jlaskey@3 80 return visitor.leave(this);
jlaskey@3 81 }
jlaskey@3 82
jlaskey@3 83 return this;
jlaskey@3 84 }
jlaskey@3 85
jlaskey@3 86 @Override
jlaskey@3 87 public void toString(final StringBuilder sb) {
jlaskey@3 88 sb.append("throw ");
jlaskey@3 89
jlaskey@3 90 if (expression != null) {
jlaskey@3 91 expression.toString(sb);
jlaskey@3 92 }
jlaskey@3 93 }
jlaskey@3 94
jlaskey@3 95 /**
jlaskey@3 96 * Get the expression that is being thrown by this node
jlaskey@3 97 * @return expression
jlaskey@3 98 */
jlaskey@3 99 public Node getExpression() {
jlaskey@3 100 return expression;
jlaskey@3 101 }
jlaskey@3 102
jlaskey@3 103 /**
jlaskey@3 104 * Reset the expression being thrown by this node
jlaskey@3 105 * @param expression new expression
jlaskey@3 106 */
jlaskey@3 107 public void setExpression(final Node expression) {
jlaskey@3 108 this.expression = expression;
jlaskey@3 109 }
jlaskey@3 110
jlaskey@3 111 /**
jlaskey@3 112 * Get surrounding tryChain for this node
jlaskey@3 113 * @return try chain
jlaskey@3 114 */
jlaskey@3 115 public TryNode getTryChain() {
jlaskey@3 116 return tryChain;
jlaskey@3 117 }
jlaskey@3 118 }

mercurial