use of org.wso2.ballerinalang.compiler.tree.statements.BLangCompoundAssignment in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangCompoundAssignment compoundAssignment) {
List<BType> expTypes = new ArrayList<>();
BLangExpression varRef = compoundAssignment.varRef;
if (varRef.getKind() != NodeKind.SIMPLE_VARIABLE_REF && varRef.getKind() != NodeKind.INDEX_BASED_ACCESS_EXPR && varRef.getKind() != NodeKind.FIELD_BASED_ACCESS_EXPR && varRef.getKind() != NodeKind.XML_ATTRIBUTE_ACCESS_EXPR) {
dlog.error(varRef.pos, DiagnosticCode.INVALID_VARIABLE_ASSIGNMENT, varRef);
expTypes.add(symTable.errType);
} else {
this.typeChecker.checkExpr(varRef, env).get(0);
expTypes.add(varRef.type);
}
this.typeChecker.checkExpr(compoundAssignment.expr, env).get(0);
if (expTypes.get(0) != symTable.errType && compoundAssignment.expr.type != symTable.errType) {
BSymbol opSymbol = this.symResolver.resolveBinaryOperator(compoundAssignment.opKind, expTypes.get(0), compoundAssignment.expr.type);
if (opSymbol == symTable.notFoundSymbol) {
dlog.error(compoundAssignment.pos, DiagnosticCode.BINARY_OP_INCOMPATIBLE_TYPES, compoundAssignment.opKind, expTypes.get(0), compoundAssignment.expr.type);
} else {
compoundAssignment.modifiedExpr = getBinaryExpr(varRef, compoundAssignment.expr, compoundAssignment.opKind, opSymbol);
this.types.checkTypes(compoundAssignment.modifiedExpr, Lists.of(compoundAssignment.modifiedExpr.type), expTypes);
}
}
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangCompoundAssignment in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addCompoundAssignmentStatement.
public void addCompoundAssignmentStatement(DiagnosticPos pos, Set<Whitespace> ws, String operator) {
BLangCompoundAssignment assignmentNode = (BLangCompoundAssignment) TreeBuilder.createCompoundAssignmentNode();
assignmentNode.setExpression(exprNodeStack.pop());
assignmentNode.setVariable((BLangVariableReference) exprNodeStack.pop());
assignmentNode.pos = pos;
assignmentNode.addWS(ws);
assignmentNode.opKind = OperatorKind.valueFrom(operator);
addStmtToCurrentBlock(assignmentNode);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangCompoundAssignment in project ballerina by ballerina-lang.
the class Desugar method visit.
public void visit(BLangCompoundAssignment compoundAssignment) {
BLangAssignment assignStmt = (BLangAssignment) TreeBuilder.createAssignmentNode();
assignStmt.pos = compoundAssignment.pos;
assignStmt.addVariable(rewriteExpr((BLangVariableReference) compoundAssignment.varRef));
assignStmt.expr = rewriteExpr(compoundAssignment.modifiedExpr);
result = assignStmt;
}
Aggregations