summaryrefslogtreecommitdiff
path: root/Homework/cs5300/p4-formatter/submit/ast/Immutable.java
blob: d94ec2c6c5ff21df488564632f8340f0b6acd53b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package submit.ast;

public class Immutable implements Expression, Node {
    private Expression expression;
    private Call call;
    private Constant constant;

    public Immutable(Expression expression) {
        this.expression = expression;
    }

    public Immutable(Call call, boolean isCall) {
        this.call = call;
    }

    public Immutable(Constant constant) {
        this.constant = constant;
    }

    @Override
    public void toCminus(StringBuilder builder, String prefix) {
        builder.append(prefix);
        if (constant != null)
            constant.toCminus(builder, "");
        if (expression != null) {
            builder.append("(");
            expression.toCminus(builder, "");
            builder.append(")");
        }
        if (call != null)
            call.toCminus(builder, "");
    }

}