| JStatementExpression.java |
1 // Copyright 2012- Bill Campbell, Swami Iyer and Bahar Akbal-Delibas
2
3 package jminusminus;
4
5 /**
6 * The AST node for an expression that appears as a statement. Only the expressions that have a
7 * side-effect are valid statement expressions.
8 */
9 class JStatementExpression extends JStatement {
10 /**
11 * The expression.
12 */
13 protected JExpression expr;
14
15 /**
16 * Constructs an AST node for a statement expression.
17 *
18 * @param line line in which the expression occurs in the source file.
19 * @param expr the expression.
20 */
21 public JStatementExpression(int line, JExpression expr) {
22 super(line);
23 this.expr = expr;
24 }
25
26 /**
27 * {@inheritDoc}
28 */
29 public JStatement analyze(Context context) {
30 if (expr.isStatementExpression) {
31 expr = expr.analyze(context);
32 }
33 return this;
34 }
35
36 /**
37 * {@inheritDoc}
38 */
39 public void codegen(CLEmitter output) {
40 expr.codegen(output);
41 }
42
43 /**
44 * {@inheritDoc}
45 */
46 public void toJSON(JSONElement json) {
47 JSONElement e = new JSONElement();
48 json.addChild("JStatementExpression:" + line, e);
49 expr.toJSON(e);
50 }
51 }
52