Search in sources :

Example 1 with CallableUnitInfo

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

the class CodeGenerator method addWorkerInfoEntry.

private void addWorkerInfoEntry(BLangWorker worker, CallableUnitInfo callableUnitInfo) {
    int workerNameCPIndex = addUTF8CPEntry(currentPkgInfo, worker.name.value);
    WorkerInfo workerInfo = new WorkerInfo(workerNameCPIndex, worker.name.value);
    callableUnitInfo.addWorkerInfo(worker.name.value, workerInfo);
}
Also used : WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 2 with CallableUnitInfo

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

the class CodeGenerator method getWorkerDataChannelInfo.

private WorkerDataChannelInfo getWorkerDataChannelInfo(CallableUnitInfo callableUnit, String source, String target) {
    WorkerDataChannelInfo workerDataChannelInfo = callableUnit.getWorkerDataChannelInfo(WorkerDataChannelInfo.generateChannelName(source, target));
    if (workerDataChannelInfo == null) {
        UTF8CPEntry sourceCPEntry = new UTF8CPEntry(source);
        int sourceCPIndex = this.currentPkgInfo.addCPEntry(sourceCPEntry);
        UTF8CPEntry targetCPEntry = new UTF8CPEntry(target);
        int targetCPIndex = this.currentPkgInfo.addCPEntry(targetCPEntry);
        workerDataChannelInfo = new WorkerDataChannelInfo(sourceCPIndex, source, targetCPIndex, target);
        workerDataChannelInfo.setUniqueName(workerDataChannelInfo.getChannelName() + this.workerChannelCount);
        String uniqueName = workerDataChannelInfo.getUniqueName();
        UTF8CPEntry uniqueNameCPEntry = new UTF8CPEntry(uniqueName);
        int uniqueNameCPIndex = this.currentPkgInfo.addCPEntry(uniqueNameCPEntry);
        workerDataChannelInfo.setUniqueNameCPIndex(uniqueNameCPIndex);
        callableUnit.addWorkerDataChannelInfo(workerDataChannelInfo);
        this.workerChannelCount++;
    }
    return workerDataChannelInfo;
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) WorkerDataChannelInfo(org.wso2.ballerinalang.programfile.WorkerDataChannelInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 3 with CallableUnitInfo

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

the class CodeGenerator method addParameterDefaultValues.

private void addParameterDefaultValues(BLangInvokableNode invokableNode, CallableUnitInfo callableUnitInfo) {
    int paramDefaultsAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE.value());
    ParamDefaultValueAttributeInfo paramDefaulValAttrInfo = new ParamDefaultValueAttributeInfo(paramDefaultsAttrNameIndex);
    // Only named parameters can have default values.
    for (BLangVariableDef param : invokableNode.defaultableParams) {
        DefaultValue defaultVal = getDefaultValue((BLangLiteral) param.var.expr);
        paramDefaulValAttrInfo.addParamDefaultValueInfo(defaultVal);
    }
    callableUnitInfo.addAttributeInfo(AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE, paramDefaulValAttrInfo);
}
Also used : DefaultValue(org.wso2.ballerinalang.programfile.DefaultValue) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 4 with CallableUnitInfo

use of org.wso2.ballerinalang.programfile.CallableUnitInfo 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 5 with CallableUnitInfo

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

the class CodeGenerator method addWorkerInfoEntries.

private void addWorkerInfoEntries(CallableUnitInfo callableUnitInfo, List<BLangWorker> workers) {
    UTF8CPEntry workerNameCPEntry = new UTF8CPEntry("default");
    int workerNameCPIndex = this.currentPkgInfo.addCPEntry(workerNameCPEntry);
    WorkerInfo defaultWorkerInfo = new WorkerInfo(workerNameCPIndex, "default");
    callableUnitInfo.defaultWorkerInfo = defaultWorkerInfo;
    for (BLangWorker worker : workers) {
        workerNameCPEntry = new UTF8CPEntry(worker.name.value);
        workerNameCPIndex = currentPkgInfo.addCPEntry(workerNameCPEntry);
        WorkerInfo workerInfo = new WorkerInfo(workerNameCPIndex, worker.getName().value);
        callableUnitInfo.addWorkerInfo(worker.getName().value, workerInfo);
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)6 BLangWorker (org.wso2.ballerinalang.compiler.tree.BLangWorker)2 DefaultValue (org.wso2.ballerinalang.programfile.DefaultValue)2 WorkerInfo (org.wso2.ballerinalang.programfile.WorkerInfo)2 ParamDefaultValueAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo)2 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)2 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)1 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)1 CallableUnitInfo (org.wso2.ballerinalang.programfile.CallableUnitInfo)1 ConnectorInfo (org.wso2.ballerinalang.programfile.ConnectorInfo)1 ImportPackageInfo (org.wso2.ballerinalang.programfile.ImportPackageInfo)1 PackageInfo (org.wso2.ballerinalang.programfile.PackageInfo)1 WorkerDataChannelInfo (org.wso2.ballerinalang.programfile.WorkerDataChannelInfo)1 LocalVariableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo)1