Search in sources :

Example 1 with BLangCompoundAssignment

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);
        }
    }
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 2 with BLangCompoundAssignment

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);
}
Also used : BLangCompoundAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangCompoundAssignment)

Example 3 with BLangCompoundAssignment

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;
}
Also used : BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)

Aggregations

ArrayList (java.util.ArrayList)1 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangVariableReference (org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference)1 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)1 BLangCompoundAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangCompoundAssignment)1