Skip to content

Commit

Permalink
🐳 chore: Upgrade swc4j to v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Nov 4, 2024
1 parent 75f25cc commit 2764f03
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 228 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object Config {
const val JAVA_VERSION = "1.8"
const val JAVET = "4.0.0"
const val JAVET_BUDDY = "0.5.0"
const val JAVET_SWC4J = "1.1.0"
const val JAVET_SWC4J = "1.2.0"
const val JUNIT = "5.11.3"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.caoccao.javet.buddy.ts2java.compiler.JavaClassCast;
import com.caoccao.javet.buddy.ts2java.compiler.JavaFunctionContext;
import com.caoccao.javet.buddy.ts2java.exceptions.Ts2JavaAstException;
import com.caoccao.javet.swc4j.ast.enums.Swc4jAstBinaryOp;
import com.caoccao.javet.swc4j.ast.expr.Swc4jAstBinExpr;
import com.caoccao.javet.swc4j.ast.expr.Swc4jAstIdent;
import com.caoccao.javet.swc4j.ast.expr.Swc4jAstUnaryExpr;
Expand Down Expand Up @@ -65,64 +66,17 @@ public TypeDescription manipulate(JavaFunctionContext functionContext, Swc4jAstB
// Add the type cast for right expression if possible.
JavaClassCast.getUpCastStackManipulation(rightType, upCaseType).ifPresent(stackManipulations::add);
StackManipulation stackManipulation;
switch (ast.getOp()) {
case Add:
stackManipulation = Ts2JavaAstBinaryOp.getAddition(upCaseType);
break;
case Div:
stackManipulation = Ts2JavaAstBinaryOp.getDivision(upCaseType);
break;
case LShift:
stackManipulation = Ts2JavaAstBinaryOp.getShiftLeft(upCaseType);
break;
case Mod:
stackManipulation = Ts2JavaAstBinaryOp.getRemainder(upCaseType);
break;
case Mul:
stackManipulation = Ts2JavaAstBinaryOp.getMultiplication(upCaseType);
break;
case RShift:
stackManipulation = Ts2JavaAstBinaryOp.getShiftRight(upCaseType);
break;
case Sub:
stackManipulation = Ts2JavaAstBinaryOp.getSubtraction(upCaseType);
break;
case ZeroFillRShift:
stackManipulation = Ts2JavaAstBinaryOp.getZeroFillShiftRight(upCaseType);
break;
case Exp:
stackManipulation = Ts2JavaAstBinaryOp.getExp();
break;
case Gt:
case GtEq:
case Lt:
case LtEq:
case EqEq:
case EqEqEq:
case NotEq:
case NotEqEq:
stackManipulation = Ts2JavaAstBinaryOp.getLogical(
functionContext, ast.getOp(), upCaseType, logicalNot);
break;
case LogicalAnd:
stackManipulation = Ts2JavaAstBinaryOp.getLogicalAndStackManipulation(
functionContext, upCaseType);
break;
case LogicalOr:
stackManipulation = Ts2JavaAstBinaryOp.getLogicalOrStackManipulation(
functionContext, upCaseType);
break;
// case BitAnd:
// stackManipulation = Ts2JavaAstBinaryOp.getBitAndStackManipulation(functionContext);
// break;
// case BitOr:
// stackManipulation = Ts2JavaAstBinaryOp.getBitOrStackManipulation(functionContext);
// break;
default:
throw new Ts2JavaAstException(
ast,
SimpleFreeMarkerFormat.format("BinExpr op ${op} is not supported.",
SimpleMap.of("op", ast.getOp().name())));
Swc4jAstBinaryOp binaryOp = ast.getOp();
if (binaryOp.isArithmeticOperator()) {
stackManipulation = Ts2JavaAstBinaryOp.getArithmetic(binaryOp, upCaseType);
} else if (binaryOp.isLogicalOperator()) {
stackManipulation = Ts2JavaAstBinaryOp.getLogical(functionContext, binaryOp, upCaseType, logicalNot);
// } else if (binaryOp.isBitOperator()) {
} else {
throw new Ts2JavaAstException(
ast,
SimpleFreeMarkerFormat.format("BinExpr op ${op} is not supported.",
SimpleMap.of("op", ast.getOp().name())));
}
stackManipulations.add(stackManipulation);
return upCaseType;
Expand Down
Loading

0 comments on commit 2764f03

Please sign in to comment.