Search in sources :

Example 1 with BLangPostIncrement

use of org.wso2.ballerinalang.compiler.tree.statements.BLangPostIncrement in project ballerina by ballerina-lang.

the class TaintAnalyzer method visit.

public void visit(BLangPostIncrement postIncrement) {
    BLangExpression varRefExpr = postIncrement.varRef;
    varRefExpr.accept(this);
    boolean varTaintedStatus = getObservedTaintedStatus();
    visitAssignment(varRefExpr, varTaintedStatus, postIncrement.pos);
}
Also used : BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 2 with BLangPostIncrement

use of org.wso2.ballerinalang.compiler.tree.statements.BLangPostIncrement in project ballerina by ballerina-lang.

the class Desugar method visit.

public void visit(BLangPostIncrement postIncrement) {
    BLangAssignment assignStmt = (BLangAssignment) TreeBuilder.createAssignmentNode();
    assignStmt.pos = postIncrement.pos;
    assignStmt.addVariable(rewriteExpr((BLangVariableReference) postIncrement.varRef));
    assignStmt.expr = rewriteExpr(postIncrement.modifiedExpr);
    result = assignStmt;
}
Also used : BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)

Example 3 with BLangPostIncrement

use of org.wso2.ballerinalang.compiler.tree.statements.BLangPostIncrement in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addPostIncrementStatement.

public void addPostIncrementStatement(DiagnosticPos pos, Set<Whitespace> ws, String operator) {
    BLangPostIncrement postIncrement = (BLangPostIncrement) TreeBuilder.createPostIncrementNode();
    postIncrement.setVariable((BLangVariableReference) exprNodeStack.pop());
    postIncrement.pos = pos;
    postIncrement.addWS(ws);
    addLiteralValue(pos, ws, TypeTags.INT, Long.parseLong("1"));
    postIncrement.increment = (BLangExpression) exprNodeStack.pop();
    postIncrement.opKind = OperatorKind.valueFrom(operator);
    addStmtToCurrentBlock(postIncrement);
}
Also used : BLangPostIncrement(org.wso2.ballerinalang.compiler.tree.statements.BLangPostIncrement)

Example 4 with BLangPostIncrement

use of org.wso2.ballerinalang.compiler.tree.statements.BLangPostIncrement in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

public void visit(BLangPostIncrement postIncrement) {
    BLangExpression varRef = postIncrement.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) {
        if (postIncrement.opKind == OperatorKind.ADD) {
            dlog.error(varRef.pos, DiagnosticCode.OPERATOR_NOT_ALLOWED_VARIABLE, OperatorKind.INCREMENT, varRef);
        } else {
            dlog.error(varRef.pos, DiagnosticCode.OPERATOR_NOT_ALLOWED_VARIABLE, OperatorKind.DECREMENT, varRef);
        }
        return;
    } else {
        this.typeChecker.checkExpr(varRef, env).get(0);
    }
    this.typeChecker.checkExpr(postIncrement.increment, env).get(0);
    if (varRef.type == symTable.intType || varRef.type == symTable.floatType) {
        BSymbol opSymbol = this.symResolver.resolveBinaryOperator(postIncrement.opKind, varRef.type, postIncrement.increment.type);
        postIncrement.modifiedExpr = getBinaryExpr(varRef, postIncrement.increment, postIncrement.opKind, opSymbol);
    } else {
        if (postIncrement.opKind == OperatorKind.ADD) {
            dlog.error(varRef.pos, DiagnosticCode.OPERATOR_NOT_SUPPORTED, OperatorKind.INCREMENT, varRef.type);
        } else {
            dlog.error(varRef.pos, DiagnosticCode.OPERATOR_NOT_SUPPORTED, OperatorKind.DECREMENT, varRef.type);
        }
    }
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Aggregations

BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)1 BLangVariableReference (org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference)1 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)1 BLangPostIncrement (org.wso2.ballerinalang.compiler.tree.statements.BLangPostIncrement)1