Search in sources :

Example 76 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.

the class TaintAnalyzer method attachTaintTableBasedOnAnnotations.

private void attachTaintTableBasedOnAnnotations(BLangConnector connectorNode) {
    if (connectorNode.symbol.taintTable == null) {
        List<Boolean> retParamsTaintedStatus = new ArrayList<>();
        Map<Integer, TaintRecord> taintTable = new HashMap<>();
        taintTable.put(ALL_UNTAINTED_TABLE_ENTRY_INDEX, new TaintRecord(retParamsTaintedStatus, null));
        if (connectorNode.params.size() > 0) {
            // Append taint table with tainted status when each parameter is tainted.
            for (int paramIndex = 0; paramIndex < connectorNode.params.size(); paramIndex++) {
                BLangVariable param = connectorNode.params.get(paramIndex);
                // If parameter is sensitive, test for this parameter being tainted is invalid.
                if (hasAnnotation(param, ANNOTATION_SENSITIVE)) {
                    continue;
                }
                taintTable.put(paramIndex, new TaintRecord(retParamsTaintedStatus, null));
            }
        }
        connectorNode.symbol.taintTable = taintTable;
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaintRecord(org.wso2.ballerinalang.compiler.semantics.model.symbols.TaintRecord) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 77 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

public void visit(BLangVariable varNode) {
    int ownerSymTag = env.scope.owner.tag;
    if ((ownerSymTag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
        // If the variable is parameter then the variable symbol is already defined
        if (varNode.symbol == null) {
            symbolEnter.defineNode(varNode, env);
        }
    }
    BType lhsType = varNode.symbol.type;
    varNode.type = lhsType;
    // Here we validate annotation attachments for package level variables.
    varNode.annAttachments.forEach(a -> {
        a.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.CONST);
        a.accept(this);
    });
    // Here we validate document attachments for package level variables.
    varNode.docAttachments.forEach(doc -> {
        doc.accept(this);
    });
    // Analyze the init expression
    BLangExpression rhsExpr = varNode.expr;
    if (rhsExpr == null) {
        return;
    }
    // Here we create a new symbol environment to catch self references by keep the current
    // variable symbol in the symbol environment
    // e.g. int a = x + a;
    SymbolEnv varInitEnv = SymbolEnv.createVarInitEnv(varNode, env, varNode.symbol);
    // It will we done during the init-function of the respective construct is visited.
    if ((ownerSymTag & SymTag.PACKAGE) == SymTag.PACKAGE || (ownerSymTag & SymTag.SERVICE) == SymTag.SERVICE || (ownerSymTag & SymTag.CONNECTOR) == SymTag.CONNECTOR) {
        return;
    }
    // Return if this not a safe assignment
    if (!varNode.safeAssignment) {
        typeChecker.checkExpr(rhsExpr, varInitEnv, Lists.of(lhsType));
        return;
    }
    handleSafeAssignment(varNode.pos, lhsType, rhsExpr, varInitEnv);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Example 78 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.

the class CodeGenerator method createTransformerInfoEntry.

private void createTransformerInfoEntry(BLangInvokableNode invokable) {
    BInvokableSymbol transformerSymbol = invokable.symbol;
    BInvokableType transformerType = (BInvokableType) transformerSymbol.type;
    // Add transformer name as an UTFCPEntry to the constant pool
    int transformerNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, transformerSymbol.name.value);
    TransformerInfo transformerInfo = new TransformerInfo(currentPackageRefCPIndex, transformerNameCPIndex);
    transformerInfo.paramTypes = transformerType.paramTypes.toArray(new BType[0]);
    transformerInfo.retParamTypes = transformerType.retTypes.toArray(new BType[0]);
    transformerInfo.flags = transformerSymbol.flags;
    this.addWorkerInfoEntries(transformerInfo, invokable.getWorkers());
    // Add parameter default value info
    addParameterDefaultValues(invokable, transformerInfo);
    transformerInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(transformerInfo.paramTypes, transformerInfo.retParamTypes));
    this.currentPkgInfo.transformerInfoMap.put(transformerSymbol.name.value, transformerInfo);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) TransformerInfo(org.wso2.ballerinalang.programfile.TransformerInfo)

Example 79 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.

the class CodeGenerator method generateNamedArgs.

private int generateNamedArgs(BLangInvocation iExpr, Operand[] operands, int currentIndex) {
    if (iExpr.namedArgs.isEmpty()) {
        return currentIndex;
    }
    PackageInfo pkgInfo = programFile.packageInfoMap.get(iExpr.symbol.pkgID.bvmAlias());
    CallableUnitInfo callableUnitInfo;
    if (iExpr.symbol.kind == SymbolKind.FUNCTION) {
        callableUnitInfo = pkgInfo.functionInfoMap.get(iExpr.symbol.name.value);
    } else if (iExpr.symbol.kind == SymbolKind.ACTION) {
        ConnectorInfo connectorInfo = pkgInfo.connectorInfoMap.get(iExpr.symbol.owner.name.value);
        callableUnitInfo = connectorInfo.actionInfoMap.get(iExpr.symbol.name.value);
    } else {
        throw new IllegalStateException("Unsupported callable unit");
    }
    ParamDefaultValueAttributeInfo defaultValAttrInfo = (ParamDefaultValueAttributeInfo) callableUnitInfo.getAttributeInfo(AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE);
    for (int i = 0; i < iExpr.namedArgs.size(); i++) {
        BLangExpression argExpr = iExpr.namedArgs.get(i);
        // at this point. If so, get the default value for that parameter from the function info.
        if (argExpr == null) {
            DefaultValue defaultVal = defaultValAttrInfo.getDefaultValueInfo()[i];
            argExpr = getDefaultValExpr(defaultVal);
        }
        operands[currentIndex++] = genNode(argExpr, this.env).regIndex;
    }
    return currentIndex;
}
Also used : DefaultValue(org.wso2.ballerinalang.programfile.DefaultValue) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) ConnectorInfo(org.wso2.ballerinalang.programfile.ConnectorInfo) ImportPackageInfo(org.wso2.ballerinalang.programfile.ImportPackageInfo) PackageInfo(org.wso2.ballerinalang.programfile.PackageInfo) CallableUnitInfo(org.wso2.ballerinalang.programfile.CallableUnitInfo) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 80 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.

the class Desugar method visit.

@Override
public void visit(BLangAction actionNode) {
    addReturnIfNotPresent(actionNode);
    SymbolEnv actionEnv = SymbolEnv.createResourceActionSymbolEnv(actionNode, actionNode.symbol.scope, env);
    // To preserve endpoint code gen order at action.
    Collections.reverse(actionNode.endpoints);
    actionNode.endpoints = rewrite(actionNode.endpoints, actionEnv);
    actionNode.body = rewrite(actionNode.body, actionEnv);
    actionNode.workers = rewrite(actionNode.workers, actionEnv);
    // we rewrite it's parameter list to have the receiver variable as the first parameter
    BInvokableSymbol actionSymbol = actionNode.symbol;
    List<BVarSymbol> params = actionSymbol.params;
    BVarSymbol receiverSymbol = actionNode.symbol.receiverSymbol;
    params.add(0, receiverSymbol);
    BInvokableType actionType = (BInvokableType) actionSymbol.type;
    if (receiverSymbol != null) {
        actionType.paramTypes.add(0, receiverSymbol.type);
    }
    result = actionNode;
}
Also used : BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Aggregations

HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)19 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)14 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)11 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)11 CharonException (org.wso2.charon3.core.exceptions.CharonException)11 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)11 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)11 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)11 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)11 Test (org.testng.annotations.Test)8 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)8 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)8 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)8 List (java.util.List)7 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)7 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)7 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)7 Parameter (org.apache.axis2.description.Parameter)6 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)6