Search in sources :

Example 11 with BLangService

use of org.wso2.ballerinalang.compiler.tree.BLangService 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 12 with BLangService

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

the class Desugar method visit.

@Override
public void visit(BLangService serviceNode) {
    SymbolEnv serviceEnv = SymbolEnv.createServiceEnv(serviceNode, serviceNode.symbol.scope, env);
    serviceNode.resources = rewrite(serviceNode.resources, serviceEnv);
    serviceNode.vars = rewrite(serviceNode.vars, serviceEnv);
    serviceNode.endpoints = rewrite(serviceNode.endpoints, serviceEnv);
    serviceNode.initFunction = rewrite(serviceNode.initFunction, serviceEnv);
    result = serviceNode;
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 13 with BLangService

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

the class EndpointDesugar method rewriteService.

private void rewriteService(BLangService service, SymbolEnv pkgEnv) {
    final BServiceSymbol serviceSymbol = (BServiceSymbol) service.symbol;
    if (serviceSymbol.boundEndpoints.isEmpty()) {
        return;
    }
    final BSymbol enclosingSymbol = pkgEnv.enclPkg.symbol;
    final BSymbol varSymbol = pkgEnv.enclPkg.startFunction.symbol;
    final BLangBlockStmt startBlock = pkgEnv.enclPkg.startFunction.body;
    serviceSymbol.boundEndpoints.forEach(endpointVarSymbol -> {
        final BLangBlockStmt generateCode = generateServiceRegistered(endpointVarSymbol, service, pkgEnv, enclosingSymbol, varSymbol);
        ASTBuilderUtil.prependStatements(generateCode, startBlock);
    });
}
Also used : BServiceSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BServiceSymbol) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)

Example 14 with BLangService

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

the class BLangPackageBuilder method startServiceDef.

public void startServiceDef(DiagnosticPos pos) {
    BLangService serviceNode = (BLangService) TreeBuilder.createServiceNode();
    serviceNode.pos = pos;
    attachAnnotations(serviceNode);
    attachDocumentations(serviceNode);
    attachDeprecatedNode(serviceNode);
    serviceNodeStack.push(serviceNode);
    startEndpointDeclarationScope(serviceNode.endpoints);
}
Also used : BLangService(org.wso2.ballerinalang.compiler.tree.BLangService)

Example 15 with BLangService

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

the class BLangPackageBuilder method endServiceDef.

public void endServiceDef(DiagnosticPos pos, Set<Whitespace> ws, String serviceName, boolean constrained) {
    BLangService serviceNode = (BLangService) serviceNodeStack.pop();
    serviceNode.setName(createIdentifier(serviceName));
    if (constrained) {
        final BLangNameReference epName = nameReferenceStack.pop();
        serviceNode.setServiceTypeStruct(createUserDefinedType(pos, epName.ws, (BLangIdentifier) epName.pkgAlias, (BLangIdentifier) epName.name));
    }
    serviceNode.pos = pos;
    serviceNode.addWS(ws);
    this.compUnit.addTopLevelNode(serviceNode);
    endEndpointDeclarationScope();
}
Also used : BLangNameReference(org.wso2.ballerinalang.compiler.tree.BLangNameReference) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier)

Aggregations

BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)16 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)7 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)7 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)6 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)6 BServiceSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BServiceSymbol)5 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)5 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)5 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)5 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)4 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)4 CompileResult (org.ballerinalang.launcher.util.CompileResult)3 PackageNode (org.ballerinalang.model.tree.PackageNode)3 Test (org.testng.annotations.Test)3 BServiceType (org.wso2.ballerinalang.compiler.semantics.model.types.BServiceType)3 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)3 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)3 BLangInvokableNode (org.wso2.ballerinalang.compiler.tree.BLangInvokableNode)3 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)3