Skip to content

Commit

Permalink
[javanaut][operationExpr][2/2]feat: Add Assignment operation expr wit…
Browse files Browse the repository at this point in the history
…h xor assignemnt (#342)

* Implement xorAssignmentWith exprs with unit test
  • Loading branch information
summer-ji-eng committed Sep 28, 2020
1 parent 89fed88 commit 118defc
Show file tree
Hide file tree
Showing 2 changed files with 608 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ private AssignmentOperationExpr build() {
}

// Check type for XOR and assignment operator (^=).
// TODO(summerji): Complete the type-checking for ^= and unit test.
if (operator.equals(OperatorKind.ASSIGNMENT_XOR)) {
Preconditions.checkState(isValidXORAssignmentType(lhsType, rhsType), errorMsg);
Preconditions.checkState(isValidXorAssignmentType(lhsType, rhsType), errorMsg);
}
return assignmentOperationExpr;
}
Expand Down Expand Up @@ -130,9 +129,25 @@ private boolean isValidMultiplyAssignmentType(TypeNode variableType, TypeNode va
return false;
}

// TODO(summerji): Complete the type-checking for ^= and unit test.
private boolean isValidXORAssignmentType(TypeNode variableType, TypeNode valueType) {
return true;
// isValidXorAssignmentType validates the types for LHS variable expr and RHS expr.
// ^= can be applied on boolean and non-floating-point numeric type.
private boolean isValidXorAssignmentType(TypeNode variableType, TypeNode valueType) {
// LHS is boolean or its boxed type, RHS should be boolean or its boxed type.
if (variableType.equals(TypeNode.BOOLEAN)) {
return valueType.equals(variableType);
}
// LHS is integer boxed type, RHS should be non-floating-point numeric types or their boxed
// types.
if (variableType.equals(TypeNode.INT)) {
return TypeNode.isNumericType(valueType) && !TypeNode.isFloatingPointType(valueType);
}
// LHS is non-floating-point numeric types, RHS should be non-float-point numeric types or
// their boxed types.
return TypeNode.isNumericType(variableType)
&& TypeNode.isNumericType(valueType)
&& !TypeNode.isFloatingPointType(variableType)
&& !TypeNode.isFloatingPointType(valueType)
&& !TypeNode.isBoxedType(variableType);
}
}
}
Loading

0 comments on commit 118defc

Please sign in to comment.