Search in sources :

Example 1 with ServiceInfo

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

the class CodeGenerator method createServiceInfoEntry.

private void createServiceInfoEntry(BLangService serviceNode) {
    // Add service name as an UTFCPEntry to the constant pool
    int serviceNameCPIndex = addUTF8CPEntry(currentPkgInfo, serviceNode.name.value);
    // Create service info
    if (serviceNode.endpointType != null) {
        String endPointQName = serviceNode.endpointType.tsymbol.toString();
        // TODO: bvmAlias needed?
        int epNameCPIndex = addUTF8CPEntry(currentPkgInfo, endPointQName);
        ServiceInfo serviceInfo = new ServiceInfo(currentPackageRefCPIndex, serviceNameCPIndex, serviceNode.symbol.flags, epNameCPIndex);
        // Add service level variables
        int localVarAttNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
        LocalVariableAttributeInfo localVarAttributeInfo = new LocalVariableAttributeInfo(localVarAttNameIndex);
        serviceNode.vars.forEach(var -> visitVarSymbol(var.var.symbol, pvIndexes, localVarAttributeInfo));
        serviceInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttributeInfo);
        // Create the init function info
        BLangFunction serviceInitFunction = (BLangFunction) serviceNode.getInitFunction();
        createFunctionInfoEntry(serviceInitFunction);
        serviceInfo.initFuncInfo = currentPkgInfo.functionInfoMap.get(serviceInitFunction.name.toString());
        currentPkgInfo.addServiceInfo(serviceNode.name.value, serviceInfo);
        // Create resource info entries for all resources
        serviceNode.resources.forEach(res -> createResourceInfoEntry(res, serviceInfo));
    }
}
Also used : ServiceInfo(org.wso2.ballerinalang.programfile.ServiceInfo) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 2 with ServiceInfo

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

the class CodeGenerator method createResourceInfoEntry.

private void createResourceInfoEntry(BLangResource resourceNode, ServiceInfo serviceInfo) {
    BInvokableType resourceType = (BInvokableType) resourceNode.symbol.type;
    // Add resource name as an UTFCPEntry to the constant pool
    int serviceNameCPIndex = addUTF8CPEntry(currentPkgInfo, resourceNode.name.value);
    ResourceInfo resourceInfo = new ResourceInfo(currentPackageRefCPIndex, serviceNameCPIndex);
    resourceInfo.paramTypes = resourceType.paramTypes.toArray(new BType[0]);
    setParameterNames(resourceNode, resourceInfo);
    resourceInfo.retParamTypes = new BType[0];
    resourceInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(resourceInfo.paramTypes, resourceInfo.retParamTypes));
    // Add worker info
    int workerNameCPIndex = addUTF8CPEntry(currentPkgInfo, "default");
    resourceInfo.defaultWorkerInfo = new WorkerInfo(workerNameCPIndex, "default");
    resourceNode.workers.forEach(worker -> addWorkerInfoEntry(worker, resourceInfo));
    // Add resource info to the service info
    serviceInfo.resourceInfoMap.put(resourceNode.name.getValue(), resourceInfo);
}
Also used : ResourceInfo(org.wso2.ballerinalang.programfile.ResourceInfo) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)1 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)1 ResourceInfo (org.wso2.ballerinalang.programfile.ResourceInfo)1 ServiceInfo (org.wso2.ballerinalang.programfile.ServiceInfo)1 WorkerInfo (org.wso2.ballerinalang.programfile.WorkerInfo)1 LocalVariableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo)1