Search in sources :

Example 6 with LocalVariableAttributeInfo

use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.

the class CodeGenerator method processWorker.

private void processWorker(BLangInvokableNode invokableNode, WorkerInfo workerInfo, BLangBlockStmt body, LocalVariableAttributeInfo localVarAttributeInfo, SymbolEnv invokableSymbolEnv, boolean defaultWorker, VariableIndex lvIndexCopy) {
    int codeAttrNameCPIndex = this.addUTF8CPEntry(this.currentPkgInfo, AttributeInfo.Kind.CODE_ATTRIBUTE.value());
    workerInfo.codeAttributeInfo.attributeNameIndex = codeAttrNameCPIndex;
    workerInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttributeInfo);
    if (body != null) {
        localVarAttrInfo = new LocalVariableAttributeInfo(localVarAttributeInfo.attributeNameIndex);
        localVarAttrInfo.localVars = new ArrayList<>(localVarAttributeInfo.localVars);
        workerInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttrInfo);
        workerInfo.codeAttributeInfo.codeAddrs = nextIP();
        this.lvIndexes = lvIndexCopy;
        this.currentWorkerInfo = workerInfo;
        this.genNode(body, invokableSymbolEnv);
    }
    this.endWorkerInfoUnit(workerInfo.codeAttributeInfo);
    this.emit(InstructionCodes.HALT);
}
Also used : LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 7 with LocalVariableAttributeInfo

use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo 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)

Example 8 with LocalVariableAttributeInfo

use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.

the class CodeGenerator method visitInvokableNode.

private void visitInvokableNode(BLangInvokableNode invokableNode, CallableUnitInfo callableUnitInfo, SymbolEnv invokableSymbolEnv) {
    int localVarAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
    LocalVariableAttributeInfo localVarAttributeInfo = new LocalVariableAttributeInfo(localVarAttrNameIndex);
    // TODO Read annotations attached to this callableUnit
    // Add local variable indexes to the parameters and return parameters
    visitInvokableNodeParams(invokableNode.symbol, callableUnitInfo, localVarAttributeInfo);
    if (Symbols.isNative(invokableNode.symbol)) {
        this.processWorker(invokableNode, callableUnitInfo.defaultWorkerInfo, null, localVarAttributeInfo, invokableSymbolEnv, true, null);
    } else {
        // Clone lvIndex structure here. This structure contain local variable indexes of the input and
        // out parameters and they are common for all the workers.
        VariableIndex lvIndexCopy = this.copyVarIndex(lvIndexes);
        this.processWorker(invokableNode, callableUnitInfo.defaultWorkerInfo, invokableNode.body, localVarAttributeInfo, invokableSymbolEnv, true, lvIndexCopy);
        for (BLangWorker worker : invokableNode.getWorkers()) {
            this.processWorker(invokableNode, callableUnitInfo.getWorkerInfo(worker.name.value), worker.body, localVarAttributeInfo, invokableSymbolEnv, false, this.copyVarIndex(lvIndexCopy));
        }
    }
}
Also used : BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 9 with LocalVariableAttributeInfo

use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.

the class CodeGenerator method visitVarSymbol.

private void visitVarSymbol(BVarSymbol varSymbol, VariableIndex variableIndex, LocalVariableAttributeInfo localVarAttrInfo) {
    varSymbol.varIndex = getRegIndexInternal(varSymbol.type.tag, variableIndex.kind);
    LocalVariableInfo localVarInfo = getLocalVarAttributeInfo(varSymbol);
    localVarAttrInfo.localVars.add(localVarInfo);
}
Also used : LocalVariableInfo(org.wso2.ballerinalang.programfile.LocalVariableInfo)

Aggregations

LocalVariableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo)8 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)6 LocalVariableInfo (org.wso2.ballerinalang.programfile.LocalVariableInfo)4 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)3 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)2 ServiceInfo (org.wso2.ballerinalang.programfile.ServiceInfo)2 AttributeInfo (org.wso2.ballerinalang.programfile.attributes.AttributeInfo)2 CodeAttributeInfo (org.wso2.ballerinalang.programfile.attributes.CodeAttributeInfo)2 DefaultValueAttributeInfo (org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo)2 ErrorTableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo)2 LineNumberTableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.LineNumberTableAttributeInfo)2 ParamDefaultValueAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo)2 VarTypeCountAttributeInfo (org.wso2.ballerinalang.programfile.attributes.VarTypeCountAttributeInfo)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Stack (java.util.Stack)1