Search in sources :

Example 31 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

@Override
public void visit(BLangResource resourceNode) {
    BInvokableSymbol resourceSymbol = Symbols.createResourceSymbol(Flags.asMask(resourceNode.flagSet), names.fromIdNode(resourceNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
    SymbolEnv invokableEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceSymbol.scope, env);
    if (!resourceNode.getParameters().isEmpty() && resourceNode.getParameters().get(0) != null && resourceNode.getParameters().get(0).typeNode == null) {
        // This is endpoint variable. Setting temporary type for now till we find actual type at semantic phase.
        resourceNode.getParameters().get(0).type = symTable.endpointType;
    }
    defineInvokableSymbol(resourceNode, resourceSymbol, invokableEnv);
}
Also used : BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 32 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.

the class SymbolEnter method defineEndpointVarSymbol.

public BEndpointVarSymbol defineEndpointVarSymbol(DiagnosticPos pos, Set<Flag> flagSet, BType varType, Name varName, SymbolEnv env) {
    // Create variable symbol
    Scope enclScope = env.scope;
    BEndpointVarSymbol varSymbol = new BEndpointVarSymbol(Flags.asMask(flagSet), varName, env.enclPkg.symbol.pkgID, varType, enclScope.owner);
    // Find duplicates
    if (!symResolver.checkForUniqueSymbol(pos, env, varSymbol, SymTag.VARIABLE_NAME)) {
        varSymbol.type = symTable.errType;
    }
    enclScope.define(varSymbol.name, varSymbol);
    return varSymbol;
}
Also used : Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol)

Example 33 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.

the class TaintAnalyzer method visit.

public void visit(BLangReturn returnNode) {
    List<Boolean> returnTaintedStatus = new ArrayList<>();
    if (returnNode.namedReturnVariables == null) {
        // If named returns are not used, evaluate each expression to identify the tainted status.
        for (BLangExpression expr : returnNode.exprs) {
            expr.accept(this);
            returnTaintedStatus.addAll(taintedStatusList);
        }
    } else {
        // If named returns are used, report back the tainted status of each variable.
        for (BLangVariable var : returnNode.namedReturnVariables) {
            returnTaintedStatus.add(var.symbol.tainted);
        }
    }
    if (returnTaintedStatusList == null) {
        returnTaintedStatusList = returnTaintedStatus;
    } else {
        // collective tainted status of returns.
        for (int i = 0; i < returnTaintedStatusList.size(); i++) {
            if (returnTaintedStatus.size() > i && returnTaintedStatus.get(i)) {
                returnTaintedStatusList.set(i, true);
            }
        }
    }
    taintedStatusList = returnTaintedStatusList;
}
Also used : ArrayList(java.util.ArrayList) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 34 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.

the class TaintAnalyzer method visitAssignment.

private void visitAssignment(BLangExpression varRefExpr, boolean varTaintedStatus, DiagnosticPos pos) {
    // Generate error if a global variable has been assigned with a tainted value.
    if (varTaintedStatus && varRefExpr instanceof BLangVariableReference) {
        BLangVariableReference varRef = (BLangVariableReference) varRefExpr;
        if (varRef.symbol != null && varRef.symbol.owner != null) {
            if (varRef.symbol.owner instanceof BPackageSymbol || SymbolKind.SERVICE.equals(varRef.symbol.owner.kind) || SymbolKind.CONNECTOR.equals(varRef.symbol.owner.kind)) {
                addTaintError(pos, varRef.symbol.name.value, DiagnosticCode.TAINTED_VALUE_PASSED_TO_GLOBAL_VARIABLE);
                return;
            }
        }
    }
    // TODO: Re-evaluating the full data-set (array) when a change occur.
    if (varRefExpr instanceof BLangIndexBasedAccess) {
        nonOverridingAnalysis = true;
        updatedVarRefTaintedState((BLangIndexBasedAccess) varRefExpr, varTaintedStatus);
        nonOverridingAnalysis = false;
    } else if (varRefExpr instanceof BLangFieldBasedAccess) {
        BLangFieldBasedAccess fieldBasedAccessExpr = (BLangFieldBasedAccess) varRefExpr;
        // Propagate tainted status to fields, when field symbols are present (Example: structs).
        if (fieldBasedAccessExpr.symbol != null) {
            setTaintedStatus(fieldBasedAccessExpr, varTaintedStatus);
        }
        nonOverridingAnalysis = true;
        updatedVarRefTaintedState(fieldBasedAccessExpr, varTaintedStatus);
        nonOverridingAnalysis = false;
    } else {
        BLangVariableReference varRef = (BLangVariableReference) varRefExpr;
        setTaintedStatus(varRef, varTaintedStatus);
    }
}
Also used : BLangIndexBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BLangFieldBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference)

Example 35 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.

the class TypeChecker method visit.

public void visit(BLangInvocation iExpr) {
    // e.g. foo();, foo(), foo().k;
    if (iExpr.expr == null) {
        // This is a function invocation expression. e.g. foo()
        checkFunctionInvocationExpr(iExpr);
        return;
    }
    Name pkgAlias = names.fromIdNode(iExpr.pkgAlias);
    if (pkgAlias != Names.EMPTY) {
        dlog.error(iExpr.pos, DiagnosticCode.PKG_ALIAS_NOT_ALLOWED_HERE);
        return;
    }
    // Find the variable reference expression type
    final List<BType> exprTypes = checkExpr(iExpr.expr, this.env, Lists.of(symTable.noType));
    if (isIterableOperationInvocation(iExpr)) {
        iExpr.iterableOperationInvocation = true;
        iterableAnalyzer.handlerIterableOperation(iExpr, expTypes.isEmpty() ? symTable.voidType : expTypes.get(0), env);
        if (iExpr.iContext.operations.getLast().resultType == symTable.voidType) {
            resultTypes = Collections.emptyList();
        } else {
            resultTypes = Lists.of(iExpr.iContext.operations.getLast().resultType);
        }
        return;
    }
    if (iExpr.actionInvocation) {
        if (exprTypes.size() != 1) {
            dlog.error(iExpr.expr.pos, DiagnosticCode.SINGLE_VALUE_RETURN_EXPECTED);
        }
        checkActionInvocationExpr(iExpr, exprTypes.size() > 0 ? exprTypes.get(0) : symTable.errType);
        return;
    }
    switch(iExpr.expr.type.tag) {
        case TypeTags.STRUCT:
            // Invoking a function bound to a struct
            // First check whether there exist a function with this name
            // Then perform arg and param matching
            checkFunctionInvocationExpr(iExpr, (BStructType) iExpr.expr.type);
            break;
        case TypeTags.CONNECTOR:
            dlog.error(iExpr.pos, DiagnosticCode.INVALID_ACTION_INVOCATION_SYNTAX);
            resultTypes = getListWithErrorTypes(expTypes.size());
            return;
        case TypeTags.BOOLEAN:
        case TypeTags.STRING:
        case TypeTags.INT:
        case TypeTags.FLOAT:
        case TypeTags.BLOB:
        case TypeTags.XML:
            checkFunctionInvocationExpr(iExpr, iExpr.expr.type);
            break;
        case TypeTags.JSON:
            checkFunctionInvocationExpr(iExpr, symTable.jsonType);
            break;
        case TypeTags.TABLE:
            checkFunctionInvocationExpr(iExpr, symTable.tableType);
            break;
        case TypeTags.STREAM:
            checkFunctionInvocationExpr(iExpr, symTable.streamType);
            break;
        case TypeTags.FUTURE:
            checkFunctionInvocationExpr(iExpr, symTable.futureType);
            break;
        case TypeTags.NONE:
            dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_FUNCTION, iExpr.name);
            break;
        case TypeTags.MAP:
            // allow map function for both constrained / un constrained maps
            checkFunctionInvocationExpr(iExpr, this.symTable.mapType);
            break;
        case TypeTags.ERROR:
            break;
        case TypeTags.INTERMEDIATE_COLLECTION:
            dlog.error(iExpr.pos, DiagnosticCode.INVALID_FUNCTION_INVOCATION_WITH_NAME, iExpr.name, iExpr.expr.type);
            resultTypes = getListWithErrorTypes(expTypes.size());
            break;
        default:
            dlog.error(iExpr.pos, DiagnosticCode.INVALID_FUNCTION_INVOCATION, iExpr.expr.type);
            resultTypes = getListWithErrorTypes(expTypes.size());
            break;
    }
// TODO other types of invocation expressions
// TODO pkg alias should be null or empty here.
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Aggregations

RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)37 ArrayList (java.util.ArrayList)31 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)31 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)30 Test (org.testng.annotations.Test)28 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)26 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)26 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)26 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)23 BJSON (org.ballerinalang.model.values.BJSON)22 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)18 IOException (java.io.IOException)17 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)17 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)17 Variable (org.wso2.siddhi.query.api.expression.Variable)17 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)16 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)15 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)15 Response (javax.ws.rs.core.Response)14 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)13