Skip to content

Commit

Permalink
🦄 refactor: Redesign ast 48
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Dec 12, 2024
1 parent 2e7233f commit c439656
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ public Swc4jAstBinaryOp getOp() {
public ITs2JavaAstExpr<?, ?> getRight() {
return right;
}

public boolean isTopBinExpr() {
return parent == null || !(parent instanceof Ts2JavaAstBinExpr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public boolean isLabelSwitched() {
public abstract boolean isLabelTrueRequired();

protected Size logicalClose(MethodVisitor methodVisitor) {
if (!(parent instanceof Ts2JavaAstBinExpr)) {
if (isTopBinExpr()) {
// This is the top bin expr. Let's close it.
Label labelClose = new Label();
if (isLabelTrueRequired()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.caoccao.javet.buddy.ts2java.ast.expr;

import com.caoccao.javet.buddy.ts2java.ast.interfaces.ITs2JavaAst;
import com.caoccao.javet.buddy.ts2java.ast.interfaces.abilities.ITs2JavaBangFlippable;
import com.caoccao.javet.buddy.ts2java.ast.memo.Ts2JavaMemoFunction;
import com.caoccao.javet.buddy.ts2java.exceptions.Ts2JavaAstException;
import com.caoccao.javet.swc4j.ast.enums.Swc4jAstBinaryOp;
Expand Down Expand Up @@ -54,10 +53,18 @@ public Size apply(MethodVisitor methodVisitor, Implementation.Context context) {
if (!isLeftLogical) {
methodVisitor.visitJumpInsn(opcodeCompareFalse, labelFalse);
}
if (!isTopBinExpr() && isRightLogical) {
right.as(Ts2JavaAstBinExprLogical.class).setLabelSwitched(true);
}
sizes.add(right.apply(methodVisitor, context));
if (!isRightLogical) {
methodVisitor.visitJumpInsn(opcodeCompareFalse, labelFalse);
}
// if (!isTopBinExpr() && isLeftLogical) {
// Ts2JavaAstBinExprLogical leftLogical = left.as(Ts2JavaAstBinExprLogical.class);
// methodVisitor.visitLabel(labelFalse);
// methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
// }
break;
}
case LogicalOr: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public boolean not_LogicalAnd_ZZ_Z(boolean a, boolean b) {
return !(a || b);
}

// @Test
// @Test
public void testLogicalAndOrAnd_II_Z() throws Exception {
enableLogging();
assertTrue(logicalAndOrAnd_II_Z(2, 2));
Expand Down

0 comments on commit c439656

Please sign in to comment.