-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignExpr.java
More file actions
89 lines (76 loc) · 2.1 KB
/
Copy pathAssignExpr.java
File metadata and controls
89 lines (76 loc) · 2.1 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package jtree.nodes;
import java.util.function.Consumer;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
@EqualsAndHashCode
@Getter @Setter
public class AssignExpr extends Node implements Expression {
protected @NonNull Expression assigned;
protected @NonNull AssignExpr.Op operation;
private @NonNull Expression value;
public AssignExpr(Expression assigned, Expression value) {
this(assigned, AssignExpr.Op.NONE, value);
}
public AssignExpr(Expression assigned, AssignExpr.Op operation, Expression value) {
setAssigned(assigned);
setOperation(operation);
setValue(value);
}
@Override
public Precedence precedence() {
return Precedence.ASSIGNMENT;
}
@Override
public AssignExpr clone() {
return new AssignExpr(getAssigned().clone(), getOperation(), getValue().clone());
}
@Override
public String toCode() {
return wrap(getAssigned()).toCode() + " " + getOperation() + " " + wrap(getValue()).toCode();
}
@RequiredArgsConstructor
public static enum Op {
NONE("="),
PLUS("+="),
MINUS("-="),
TIMES("*="),
DIVIDE("/="),
MODULUS("%="),
XOR("^="),
AND("&="),
OR("|="),
LSHIFT("<<="),
RSHIFT(">>="),
URSHIFT(">>>=");
@Getter @Accessors(fluent = true)
protected final String toString;
public static Op fromString(String op) {
return switch(op) {
case "=" -> NONE;
case "+=" -> PLUS;
case "-=" -> MINUS;
case "*=" -> TIMES;
case "/=" -> DIVIDE;
case "%=" -> MODULUS;
case "^=" -> XOR;
case "&=" -> AND;
case "|=" -> OR;
case "<<=" -> LSHIFT;
case ">>=" -> RSHIFT;
case ">>>=" -> URSHIFT;
default -> throw new IllegalArgumentException("No operator corresponding to " + op + " found");
};
}
}
@Override
public <N extends INode> void accept(TreeVisitor visitor, Node parent, Consumer<N> replacer) {
if(visitor.visitAssignExpr(this, parent, cast(replacer))) {
getAssigned().accept(visitor, this, this::setAssigned);
getValue().accept(visitor, this, this::setValue);
}
}
}