Skip to content

Commit

Permalink
✨ feat: Enhance binary op
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Nov 3, 2024
1 parent 6e49388 commit b09602e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release Notes

## 1.0.1
## 1.1.0

* Upgraded deno_ast to v0.42.2
* Upgraded rust toolchain to v1.81.0
Expand Down
118 changes: 90 additions & 28 deletions src/main/java/com/caoccao/javet/swc4j/ast/enums/Swc4jAstBinaryOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,78 @@
import java.util.stream.Stream;

public enum Swc4jAstBinaryOp implements ISwc4jEnumIdName {
Add(0, "+", false),
BitAnd(1, "&", false),
BitOr(2, "|", false),
BitXor(3, "^", false),
Div(4, "/", false),
EqEq(5, "==", false),
EqEqEq(6, "===", false),
Exp(7, "**", false),
Gt(8, ">", false),
GtEq(9, ">=", false),
In(10, "in", true),
InstanceOf(11, "instanceof", true),
LogicalAnd(12, "&&", false),
LogicalOr(13, "||", false),
LShift(14, "<<", false),
Lt(15, "<", false),
LtEq(16, "<=", false),
Mod(17, "%", false),
Mul(18, "*", false),
NotEq(19, "!=", false),
NotEqEq(20, "!==", false),
NullishCoalescing(21, "??", false),
RShift(22, ">>", false),
Sub(23, "-", false),
ZeroFillRShift(24, ">>>", false),
Add(0, "+"),
BitAnd(1, "&"),
BitOr(2, "|"),
BitXor(3, "^"),
Div(4, "/"),
EqEq(5, "=="),
EqEqEq(6, "==="),
Exp(7, "**"),
Gt(8, ">"),
GtEq(9, ">="),
In(10, "in"),
InstanceOf(11, "instanceof"),
LogicalAnd(12, "&&"),
LogicalOr(13, "||"),
LShift(14, "<<"),
Lt(15, "<"),
LtEq(16, "<="),
Mod(17, "%"),
Mul(18, "*"),
NotEq(19, "!="),
NotEqEq(20, "!=="),
NullishCoalescing(21, "??"),
RShift(22, ">>"),
Sub(23, "-"),
ZeroFillRShift(24, ">>>"),
;

private static final int LENGTH = values().length;
private static final Swc4jAstBinaryOp[] TYPES = new Swc4jAstBinaryOp[LENGTH];

static {
Add.setArithmeticOperator();
BitAnd.setBitOperator();
BitOr.setBitOperator();
BitXor.setBitOperator();
Div.setArithmeticOperator();
EqEq.setLogicalOperator();
EqEqEq.setLogicalOperator();
Exp.setArithmeticOperator();
Gt.setLogicalOperator();
GtEq.setLogicalOperator();
In.setSpaceRequired();
InstanceOf.setSpaceRequired();
LogicalAnd.setLogicalOperator();
LogicalOr.setLogicalOperator();
LShift.setArithmeticOperator();
Lt.setLogicalOperator();
LtEq.setLogicalOperator();
Mod.setArithmeticOperator();
Mul.setArithmeticOperator();
NotEq.setLogicalOperator();
NotEqEq.setLogicalOperator();
RShift.setArithmeticOperator();
Sub.setArithmeticOperator();
ZeroFillRShift.setArithmeticOperator();
Stream.of(values()).forEach(v -> TYPES[v.getId()] = v);
}

private final int id;
private final String name;
private final boolean spaceRequired;
private boolean arithmeticOperator;
private boolean bitOperator;
private boolean logicalOperator;
private boolean spaceRequired;

Swc4jAstBinaryOp(int id, String name, boolean spaceRequired) {
Swc4jAstBinaryOp(int id, String name) {
arithmeticOperator = false;
bitOperator = false;
this.id = id;
logicalOperator = false;
this.name = name;
this.spaceRequired = spaceRequired;
spaceRequired = false;
}

public static Swc4jAstBinaryOp parse(int id) {
Expand All @@ -79,7 +109,39 @@ public String getName() {
return name;
}

public boolean isArithmeticOperator() {
return arithmeticOperator;
}

public boolean isBitOperator() {
return bitOperator;
}

public boolean isLogicalOperator() {
return logicalOperator;
}

public boolean isSpaceRequired() {
return spaceRequired;
}

private Swc4jAstBinaryOp setArithmeticOperator() {
this.arithmeticOperator = true;
return this;
}

private Swc4jAstBinaryOp setBitOperator() {
this.bitOperator = true;
return this;
}

private Swc4jAstBinaryOp setLogicalOperator() {
this.logicalOperator = true;
return this;
}

private Swc4jAstBinaryOp setSpaceRequired() {
this.spaceRequired = true;
return this;
}
}

0 comments on commit b09602e

Please sign in to comment.