Search in sources :

Example 31 with BLangFunction

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

the class TaintAnalyzer method visitInvokable.

private void visitInvokable(BLangFunction invNode, SymbolEnv symbolEnv) {
    if (invNode.symbol.taintTable == null) {
        if (Symbols.isNative(invNode.symbol) || invNode.interfaceFunction) {
            attachTaintTableBasedOnAnnotations(invNode);
            return;
        }
        Map<Integer, TaintRecord> taintTable = new HashMap<>();
        returnTaintedStatusList = null;
        // Check the tainted status of return values when no parameter is tainted.
        analyzeAllParamsUntaintedReturnTaintedStatus(taintTable, invNode, symbolEnv);
        boolean isBlocked = processBlockedNode(invNode);
        if (isBlocked) {
            return;
        }
        int requiredParamCount = invNode.requiredParams.size();
        int defaultableParamCount = invNode.defaultableParams.size();
        int totalParamCount = requiredParamCount + defaultableParamCount + (invNode.restParam == null ? 0 : 1);
        for (int paramIndex = 0; paramIndex < totalParamCount; paramIndex++) {
            BLangVariable param = getParam(invNode, paramIndex, requiredParamCount, defaultableParamCount);
            // If parameter is sensitive, it is invalid to have a case where tainted status of parameter is true.
            if (hasAnnotation(param, ANNOTATION_SENSITIVE)) {
                continue;
            }
            returnTaintedStatusList = null;
            // Set each parameter "tainted", then analyze the body to observe the outcome of the function.
            analyzeReturnTaintedStatus(taintTable, invNode, symbolEnv, paramIndex, requiredParamCount, defaultableParamCount);
        }
        invNode.symbol.taintTable = taintTable;
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) TaintRecord(org.wso2.ballerinalang.compiler.semantics.model.symbols.TaintRecord) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 32 with BLangFunction

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

the class SemanticAnalyzer method visit.

public void visit(BLangFunction funcNode) {
    SymbolEnv funcEnv = SymbolEnv.createFunctionEnv(funcNode, funcNode.symbol.scope, env);
    funcNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.FUNCTION);
        this.analyzeDef(annotationAttachment, funcEnv);
    });
    funcNode.docAttachments.forEach(doc -> analyzeDef(doc, funcEnv));
    funcNode.requiredParams.forEach(p -> this.analyzeDef(p, funcEnv));
    funcNode.defaultableParams.forEach(p -> this.analyzeDef(p, funcEnv));
    if (funcNode.restParam != null) {
        this.analyzeDef(funcNode.restParam, funcEnv);
    }
    // Check for native functions
    if (Symbols.isNative(funcNode.symbol) || funcNode.interfaceFunction) {
        return;
    }
    funcNode.endpoints.forEach(e -> {
        symbolEnter.defineNode(e, funcEnv);
        analyzeDef(e, funcEnv);
    });
    analyzeStmt(funcNode.body, funcEnv);
    this.processWorkers(funcNode, funcEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Example 33 with BLangFunction

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

the class CodeGenerator method visit.

public void visit(BLangConnector connectorNode) {
    BLangFunction initFunction = (BLangFunction) connectorNode.getInitFunction();
    visit(initFunction);
    currentConnectorInfo = currentPkgInfo.getConnectorInfo(connectorNode.getName().getValue());
    SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorNode.symbol.scope, this.env);
    connectorNode.actions.forEach(action -> genNode(action, connectorEnv));
    genNode(connectorNode.initAction, connectorEnv);
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 34 with BLangFunction

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

the class CodeGenerator method visit.

public void visit(BLangService serviceNode) {
    BLangFunction initFunction = (BLangFunction) serviceNode.getInitFunction();
    visit(initFunction);
    currentServiceInfo = currentPkgInfo.getServiceInfo(serviceNode.getName().getValue());
    SymbolEnv serviceEnv = SymbolEnv.createServiceEnv(serviceNode, serviceNode.symbol.scope, this.env);
    serviceNode.resources.forEach(resource -> genNode(resource, serviceEnv));
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 35 with BLangFunction

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

the class CodeGenerator method createConnectorInfoEntry.

private void createConnectorInfoEntry(BLangConnector connectorNode) {
    BConnectorType connectorType = (BConnectorType) connectorNode.symbol.type;
    // Add connector name as an UTFCPEntry to the constant pool
    int connectorNameCPIndex = addUTF8CPEntry(currentPkgInfo, connectorNode.name.value);
    // Create connector info
    ConnectorInfo connectorInfo = new ConnectorInfo(currentPackageRefCPIndex, connectorNameCPIndex, connectorNode.symbol.flags);
    connectorInfo.paramTypes = connectorType.paramTypes.toArray(new BType[0]);
    connectorInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateConnectorSig(connectorInfo));
    // Add connector level variables
    int localVarAttNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
    LocalVariableAttributeInfo localVarAttributeInfo = new LocalVariableAttributeInfo(localVarAttNameIndex);
    connectorNode.params.forEach(var -> visitVarSymbol(var.symbol, fieldIndexes, localVarAttributeInfo));
    connectorNode.varDefs.forEach(var -> visitVarSymbol(var.var.symbol, fieldIndexes, localVarAttributeInfo));
    connectorInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttributeInfo);
    // Create variable count attribute info
    prepareIndexes(fieldIndexes);
    int[] fieldCount = new int[] { fieldIndexes.tInt, fieldIndexes.tFloat, fieldIndexes.tString, fieldIndexes.tBoolean, fieldIndexes.tBlob, fieldIndexes.tRef };
    addVariableCountAttributeInfo(currentPkgInfo, connectorInfo, fieldCount);
    // Create the init function info
    BLangFunction connectorInitFunction = (BLangFunction) connectorNode.getInitFunction();
    createFunctionInfoEntry(connectorInitFunction);
    this.currentPkgInfo.connectorInfoMap.put(connectorNode.name.value, connectorInfo);
    // Create action info entries for all actions
    connectorNode.actions.forEach(res -> createActionInfoEntry(res, connectorInfo));
    createActionInfoEntry(connectorNode.initAction, connectorInfo);
    fieldIndexes = new VariableIndex(FIELD);
}
Also used : LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) ConnectorInfo(org.wso2.ballerinalang.programfile.ConnectorInfo) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)37 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)24 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)16 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)16 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)15 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)15 ArrayList (java.util.ArrayList)14 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)14 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)13 List (java.util.List)11 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)10 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)10 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)10 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)9 BLangEnum (org.wso2.ballerinalang.compiler.tree.BLangEnum)9 BLangObject (org.wso2.ballerinalang.compiler.tree.BLangObject)9 BLangReturn (org.wso2.ballerinalang.compiler.tree.statements.BLangReturn)9 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)9 Collectors (java.util.stream.Collectors)8 NodeKind (org.ballerinalang.model.tree.NodeKind)8