public static Expr unary(UnaryOperation op, OperationType type, Expr arg) { UnaryExpr expr = new UnaryExpr(); expr.setOperand(arg); expr.setOperation(op); expr.setType(type); return expr; }
@Override public void visit(UnaryExpr expr) { pushLocation(expr.getLocation()); try { expr.getOperand().acceptVisitor(this); Expr operand = resultExpr; if (expr.getOperation() == UnaryOperation.NEGATE && operand instanceof ConstantExpr) { ConstantExpr constantExpr = (ConstantExpr) operand; if (tryMakePositive(constantExpr)) { resultExpr = expr; return; } } expr.setOperand(operand); resultExpr = expr; } finally { popLocation(); } }
@Override public void visit(UnaryExpr expr) { try { output.writeByte(1); output.writeByte(expr.getOperation().ordinal()); output.writeByte(expr.getType() != null ? expr.getType().ordinal() + 1 : 0); writeExpr(expr.getOperand()); } catch (IOException e) { throw new IOExceptionWrapper(e); } }
public static Expr invert(Expr expr) { UnaryExpr result = new UnaryExpr(); result.setOperand(expr); result.setOperation(UnaryOperation.NOT); result.setLocation(expr.getLocation()); return result; }
@Override public void visit(UnaryExpr expr) { switch (expr.getOperation()) { case INT_TO_BYTE: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(24)); result.setLocation(expr.getLocation()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHR_SIGNED, result, new WasmInt32Constant(24)); result.setLocation(expr.getLocation()); break; case INT_TO_SHORT: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(16)); result.setLocation(expr.getLocation()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHR_SIGNED, result, new WasmInt32Constant(16)); result.setLocation(expr.getLocation()); break; case INT_TO_CHAR: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(16)); result.setLocation(expr.getLocation()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHR_UNSIGNED, result, new WasmInt32Constant(16)); result.setLocation(expr.getLocation()); break;
@Override public void visit(UnaryExpr expr) { switch (expr.getOperation()) { case NOT: writer.print("("); writer.print("!"); expr.getOperand().acceptVisitor(this); writer.print(")"); break; writer.print("("); writer.print("-"); expr.getOperand().acceptVisitor(this); writer.print(")"); break; case LENGTH: writer.print("ARRAY_LENGTH("); expr.getOperand().acceptVisitor(this); writer.print(")"); break; case NULL_CHECK: expr.getOperand().acceptVisitor(this); break; case INT_TO_BYTE: writer.print("TO_BYTE("); expr.getOperand().acceptVisitor(this); writer.print(")"); break; case INT_TO_SHORT: writer.print("TO_SHORT(");
@Override public void visit(UnaryExpr expr) { expr.getOperand().acceptVisitor(this); }
@Override public void visit(UnaryExpr expr) { super.visit(expr); switch (expr.getOperation()) { case NULL_CHECK: consumer.consumeFunction("$rt_nullCheck"); break; default: break; } }
@Override public void visit(UnaryExpr expr) { try { if (expr.getLocation() != null) { pushLocation(expr.getLocation()); switch (expr.getOperation()) { case NOT: { if (expr.getType() == OperationType.LONG) { longLibraryUsed = true; writer.append("Long_not("); precedence = Precedence.min(); expr.getOperand().acceptVisitor(this); writer.append(')'); } else { writer.append(expr.getType() == null ? "!" : "~"); precedence = Precedence.UNARY; expr.getOperand().acceptVisitor(this); if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) { writer.append(')'); if (expr.getType() == OperationType.LONG) { longLibraryUsed = true; writer.append("Long_neg("); precedence = Precedence.min(); expr.getOperand().acceptVisitor(this); writer.append(')'); } else {
public static Expr invert(Expr expr) { UnaryExpr result = new UnaryExpr(); result.setOperand(expr); result.setOperation(UnaryOperation.NOT); result.setLocation(expr.getLocation()); return result; }
public static Expr invert(Expr expr) { if (expr instanceof UnaryExpr) { UnaryExpr unary = (UnaryExpr) expr; if (unary.getOperation() == UnaryOperation.NOT) { return unary.getOperand(); } } else if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; Expr a = binary.getFirstOperand(); Expr b = binary.getSecondOperand(); switch (binary.getOperation()) { case EQUALS: return Expr.binary(BinaryOperation.NOT_EQUALS, binary.getType(), a, b, expr.getLocation()); case NOT_EQUALS: return Expr.binary(BinaryOperation.EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS: return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS_OR_EQUALS: return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b, expr.getLocation()); case GREATER: return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case GREATER_OR_EQUALS: return Expr.binary(BinaryOperation.LESS, binary.getType(), a, b, expr.getLocation()); default: break; } } return Expr.invert(expr); } }
private boolean isSideEffectFree(Expr expr) { if (expr == null) { return true; } if (expr instanceof VariableExpr || expr instanceof ConstantExpr) { return true; } if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; return isSideEffectFree(binary.getFirstOperand()) && isSideEffectFree(binary.getSecondOperand()); } if (expr instanceof UnaryExpr) { return isSideEffectFree(((UnaryExpr) expr).getOperand()); } if (expr instanceof InstanceOfExpr) { return isSideEffectFree(((InstanceOfExpr) expr).getExpr()); } if (expr instanceof PrimitiveCastExpr) { return isSideEffectFree(((PrimitiveCastExpr) expr).getValue()); } if (expr instanceof NewExpr) { return true; } return false; }
@Override public void visit(UnaryExpr expr) { super.visit(expr); switch (expr.getOperation()) { case NULL_CHECK: consumer.consumeFunction("$rt_nullCheck"); break; default: break; } }
@Override protected Expr clone(Map<Expr, Expr> cache) { Expr known = cache.get(this); if (known != null) { return known; } UnaryExpr copy = new UnaryExpr(); copy.setOperation(operation); copy.setOperand(operand != null ? operand.clone(cache) : null); copy.setType(type); return copy; } }
@Override public void visit(UnaryExpr expr) { switch (expr.getOperation()) { case INT_TO_BYTE: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(24)); result.setLocation(expr.getLocation()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHR_SIGNED, result, new WasmInt32Constant(24)); result.setLocation(expr.getLocation()); break; case INT_TO_SHORT: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(16)); result.setLocation(expr.getLocation()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHR_SIGNED, result, new WasmInt32Constant(16)); result.setLocation(expr.getLocation()); break; case INT_TO_CHAR: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(16)); result.setLocation(expr.getLocation()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHR_UNSIGNED, result, new WasmInt32Constant(16)); result.setLocation(expr.getLocation()); break;
@Override public void visit(UnaryExpr expr) { pushLocation(expr.getLocation()); try { expr.getOperand().acceptVisitor(this); Expr operand = resultExpr; if (expr.getOperation() == UnaryOperation.NEGATE && operand instanceof ConstantExpr) { ConstantExpr constantExpr = (ConstantExpr) operand; if (tryMakePositive(constantExpr)) { resultExpr = expr; return; } } expr.setOperand(operand); resultExpr = expr; } finally { popLocation(); } }
@Override public void visit(UnaryExpr expr) { try { output.writeByte(1); output.writeByte(expr.getOperation().ordinal()); output.writeByte(expr.getType() != null ? expr.getType().ordinal() + 1 : 0); writeExpr(expr.getOperand()); } catch (IOException e) { throw new IOExceptionWrapper(e); } }
public static Expr invert(Expr expr) { if (expr instanceof UnaryExpr) { UnaryExpr unary = (UnaryExpr) expr; if (unary.getOperation() == UnaryOperation.NOT) { return unary.getOperand(); } } else if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; Expr a = binary.getFirstOperand(); Expr b = binary.getSecondOperand(); switch (binary.getOperation()) { case EQUALS: return Expr.binary(BinaryOperation.NOT_EQUALS, binary.getType(), a, b, expr.getLocation()); case NOT_EQUALS: return Expr.binary(BinaryOperation.EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS: return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS_OR_EQUALS: return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b); case GREATER: return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case GREATER_OR_EQUALS: return Expr.binary(BinaryOperation.LESS, binary.getType(), a, b, expr.getLocation()); default: break; } } return Expr.invert(expr); } }
@Override public void visit(UnaryExpr expr) { expr.getOperand().acceptVisitor(this); }
UnaryExpr expr = new UnaryExpr(); expr.setOperation(unaryOperations[input.readByte()]); byte valueType = input.readByte(); expr.setType(valueType > 0 ? OperationType.values()[valueType] : null); expr.setOperand(readExpr(input)); return expr;