1/*
2 * Copyright (c) 1994, 2003, 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
26package sun.tools.tree;
27
28import sun.tools.java.*;
29import sun.tools.asm.Assembler;
30import java.io.PrintStream;
31import java.util.Hashtable;
32
33/**
34 * WARNING: The contents of this source file are not part of any
35 * supported API.  Code that depends on them does so at its own risk:
36 * they are subject to change or removal without notice.
37 */
38public
39class ExpressionStatement extends Statement {
40    Expression expr;
41
42    /**
43     * Constructor
44     */
45    public ExpressionStatement(long where, Expression expr) {
46        super(EXPRESSION, where);
47        this.expr = expr;
48    }
49
50    /**
51     * Check statement
52     */
53    Vset check(Environment env, Context ctx, Vset vset, Hashtable<Object, Object> exp) {
54        checkLabel(env, ctx);
55        return expr.check(env, ctx, reach(env, vset), exp);
56    }
57
58    /**
59     * Inline
60     */
61    public Statement inline(Environment env, Context ctx) {
62        if (expr != null) {
63            expr = expr.inline(env, ctx);
64            return (expr == null) ? null : this;
65        }
66        return null;
67    }
68
69    /**
70     * Create a copy of the statement for method inlining
71     */
72    public Statement copyInline(Context ctx, boolean valNeeded) {
73        ExpressionStatement s = (ExpressionStatement)clone();
74        s.expr = expr.copyInline(ctx);
75        return s;
76    }
77
78    /**
79     * The cost of inlining this statement
80     */
81    public int costInline(int thresh, Environment env, Context ctx) {
82        return expr.costInline(thresh, env, ctx);
83    }
84
85    /**
86     * Code
87     */
88    public void code(Environment env, Context ctx, Assembler asm) {
89        expr.code(env, ctx, asm);
90    }
91
92    /**
93     * Check if the first thing is a constructor invocation
94     */
95    public Expression firstConstructor() {
96        return expr.firstConstructor();
97    }
98
99    /**
100     * Print
101     */
102    public void print(PrintStream out, int indent) {
103        super.print(out, indent);
104        if (expr != null) {
105            expr.print(out);
106        } else {
107            out.print("<empty>");
108        }
109        out.print(";");
110    }
111}
112