Search in sources :

Example 1 with BLangLambdaFunction

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction in project ballerina by ballerina-lang.

the class TaintAnalyzer method analyzeLambdaExpressions.

private void analyzeLambdaExpressions(BLangInvocation invocationExpr, BLangExpression argExpr) {
    BLangFunction function = ((BLangLambdaFunction) argExpr).function;
    if (function.symbol.taintTable == null) {
        addToBlockedList(invocationExpr);
    } else {
        int requiredParamCount = function.requiredParams.size();
        int defaultableParamCount = function.defaultableParams.size();
        int totalParamCount = requiredParamCount + defaultableParamCount + (function.restParam == null ? 0 : 1);
        Map<Integer, TaintRecord> taintTable = function.symbol.taintTable;
        for (int paramIndex = 0; paramIndex < totalParamCount; paramIndex++) {
            TaintRecord taintRecord = taintTable.get(paramIndex);
            BLangVariable param = getParam(function, paramIndex, requiredParamCount, defaultableParamCount);
            if (taintRecord == null) {
                addTaintError(argExpr.pos, param.name.value, DiagnosticCode.TAINTED_VALUE_PASSED_TO_SENSITIVE_PARAMETER);
            } else if (taintRecord.taintError != null && taintRecord.taintError.size() > 0) {
                addTaintError(taintRecord.taintError);
            }
            if (stopAnalysis) {
                break;
            }
        }
    }
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangLambdaFunction(org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction) TaintRecord(org.wso2.ballerinalang.compiler.semantics.model.symbols.TaintRecord) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 2 with BLangLambdaFunction

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addLambdaFunctionDef.

public void addLambdaFunctionDef(DiagnosticPos pos, Set<Whitespace> ws, boolean paramsAvail, boolean retParamsAvail, boolean restParamAvail) {
    BLangFunction lambdaFunction = (BLangFunction) this.invokableNodeStack.peek();
    lambdaFunction.pos = pos;
    endCallableUnitSignature(ws, lambdaFunction.getName().value, paramsAvail, retParamsAvail, restParamAvail);
    BLangLambdaFunction lambdaExpr = (BLangLambdaFunction) TreeBuilder.createLambdaFunctionNode();
    lambdaExpr.function = lambdaFunction;
    lambdaExpr.pos = pos;
    addExpressionNode(lambdaExpr);
    // TODO: is null correct here
    endFunctionDef(pos, null, false, false, true, false);
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangLambdaFunction(org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction)

Example 3 with BLangLambdaFunction

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

public void visit(BLangStreamAction streamAction) {
    BLangLambdaFunction function = (BLangLambdaFunction) streamAction.getInvokableBody();
    typeChecker.checkExpr(function, env);
}
Also used : BLangLambdaFunction(org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction)

Aggregations

BLangLambdaFunction (org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction)3 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)2 TaintRecord (org.wso2.ballerinalang.compiler.semantics.model.symbols.TaintRecord)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1