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));
}
}
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;
}
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);
});
}
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);
}
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();
}
Aggregations