use of org.wso2.ballerinalang.compiler.tree.BLangService in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangService serviceNode) {
BServiceSymbol serviceSymbol = (BServiceSymbol) serviceNode.symbol;
SymbolEnv serviceEnv = SymbolEnv.createServiceEnv(serviceNode, serviceSymbol.scope, env);
handleServiceTypeStruct(serviceNode);
handleServiceEndpointBinds(serviceNode, serviceSymbol);
serviceNode.annAttachments.forEach(a -> {
a.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.SERVICE);
this.analyzeDef(a, serviceEnv);
});
serviceNode.docAttachments.forEach(doc -> analyzeDef(doc, serviceEnv));
serviceNode.vars.forEach(v -> this.analyzeDef(v, serviceEnv));
serviceNode.endpoints.forEach(e -> {
symbolEnter.defineNode(e, serviceEnv);
analyzeDef(e, serviceEnv);
});
this.analyzeDef(serviceNode.initFunction, serviceEnv);
serviceNode.resources.forEach(r -> this.analyzeDef(r, serviceEnv));
}
use of org.wso2.ballerinalang.compiler.tree.BLangService in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangService serviceNode) {
BLangFunction initFunction = (BLangFunction) serviceNode.getInitFunction();
visit(initFunction);
currentServiceInfo = currentPkgInfo.getServiceInfo(serviceNode.getName().getValue());
SymbolEnv serviceEnv = SymbolEnv.createServiceEnv(serviceNode, serviceNode.symbol.scope, this.env);
serviceNode.resources.forEach(resource -> genNode(resource, serviceEnv));
}
use of org.wso2.ballerinalang.compiler.tree.BLangService in project ballerina by ballerina-lang.
the class AnnotationDesugar method rewritePackageAnnotations.
protected void rewritePackageAnnotations(BLangPackage pkgNode) {
BLangFunction initFunction = pkgNode.initFunction;
// Remove last return statement. we will add it later. TODO : Fix this properly.
initFunction.body.stmts.remove(initFunction.body.stmts.size() - 1);
// This is the variable which store all package level annotations.
BLangVariable annotationMap = createGlobalAnnotationMapVar(pkgNode);
// handle Service Annotations.
for (BLangService service : pkgNode.services) {
generateAnnotations(service, service.name.value, initFunction, annotationMap);
for (BLangResource resource : service.resources) {
String key = service.name.value + DOT + resource.name.value;
generateAnnotations(resource, key, initFunction, annotationMap);
}
}
// Handle Function Annotations.
for (BLangFunction function : pkgNode.functions) {
generateAnnotations(function, function.symbol.name.value, initFunction, annotationMap);
}
// Handle Connector Annotations.
for (BLangConnector connector : pkgNode.connectors) {
generateAnnotations(connector, connector.name.value, initFunction, annotationMap);
for (BLangAction action : connector.actions) {
String key = connector.name.value + DOT + action.name.value;
generateAnnotations(connector, key, initFunction, annotationMap);
}
}
// Handle Struct Annotations.
for (BLangStruct struct : pkgNode.structs) {
generateAnnotations(struct, struct.name.value, initFunction, annotationMap);
for (BLangVariable field : struct.fields) {
String key = struct.name.value + DOT + field.name.value;
generateAnnotations(field, key, initFunction, annotationMap);
}
}
for (BLangEndpoint globalEndpoint : pkgNode.globalEndpoints) {
generateAnnotations(globalEndpoint, globalEndpoint.name.value, initFunction, annotationMap);
}
ASTBuilderUtil.createReturnStmt(pkgNode.pos, initFunction.body);
}
use of org.wso2.ballerinalang.compiler.tree.BLangService in project ballerina by ballerina-lang.
the class EndpointDesugar method rewriteEndpoint.
void rewriteEndpoint(BLangEndpoint endpoint, SymbolEnv env) {
final BSymbol encSymbol, varSymbol;
final BLangBlockStmt initBlock, startBlock;
BLangBlockStmt stopBlock = null;
if (env.enclInvokable != null) {
// Function, Action, Resource. Code generate to its body directly.
encSymbol = varSymbol = env.enclInvokable.symbol;
initBlock = startBlock = ((BLangInvokableNode) env.node).body;
} else if (env.enclService != null) {
encSymbol = env.enclService.symbol;
varSymbol = ((BLangService) env.node).initFunction.symbol;
initBlock = startBlock = ((BLangService) env.node).initFunction.body;
} else {
// Pkg level endpoint.
encSymbol = env.enclPkg.symbol;
varSymbol = ((BLangPackage) env.node).initFunction.symbol;
initBlock = ((BLangPackage) env.node).initFunction.body;
startBlock = ((BLangPackage) env.node).startFunction.body;
stopBlock = ((BLangPackage) env.node).stopFunction.body;
}
BLangBlockStmt genInit, genInitCall, genStartCall, genStopCall;
genInit = generateEndpointInit(endpoint, env, encSymbol);
genInitCall = generateEndpointInitFunctionCall(endpoint, env, encSymbol, varSymbol);
genStartCall = generateEndpointStartOrStop(endpoint, endpoint.symbol.startFunction, env, encSymbol);
genStopCall = generateEndpointStartOrStop(endpoint, endpoint.symbol.stopFunction, env, encSymbol);
if (env.enclInvokable != null) {
ASTBuilderUtil.prependStatements(genStartCall, startBlock);
ASTBuilderUtil.prependStatements(genInitCall, initBlock);
// TODO : Implement stop.
ASTBuilderUtil.prependStatements(genInit, initBlock);
} else if (env.enclService != null) {
ASTBuilderUtil.appendStatements(genInit, initBlock);
ASTBuilderUtil.appendStatements(genInitCall, initBlock);
ASTBuilderUtil.appendStatements(genStartCall, startBlock);
// TODO : Implement stop.
} else {
ASTBuilderUtil.appendStatements(genInit, initBlock);
ASTBuilderUtil.appendStatements(genInitCall, initBlock);
ASTBuilderUtil.appendStatements(genStartCall, startBlock);
ASTBuilderUtil.appendStatements(genStopCall, Objects.requireNonNull(stopBlock));
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangService in project ballerina by ballerina-lang.
the class EndpointDesugar method generateServiceRegistered.
private BLangBlockStmt generateServiceRegistered(BEndpointVarSymbol endpoint, BLangService service, SymbolEnv env, BSymbol encSymbol, BSymbol varEncSymbol) {
final DiagnosticPos pos = service.pos;
final String epName = endpoint.name.value;
BLangBlockStmt temp = new BLangBlockStmt();
final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.type);
final Name name = endpoint.name;
epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, name, SymTag.VARIABLE);
final BLangVariableDef serviceTypeDef = ASTBuilderUtil.createVariableDefStmt(pos, temp);
serviceTypeDef.var = ASTBuilderUtil.createVariable(pos, service.name + "type", symTable.typeDesc);
ASTBuilderUtil.defineVariable(serviceTypeDef.var, varEncSymbol, names);
final BLangUnaryExpr typeOfExpr = ASTBuilderUtil.createUnaryExpr(pos);
serviceTypeDef.var.expr = typeOfExpr;
typeOfExpr.operator = OperatorKind.TYPEOF;
typeOfExpr.expr = getTypeAccessExpression(pos, service.symbol.type);
typeOfExpr.type = symTable.typeDesc;
List<BLangVariable> args = Lists.of(serviceTypeDef.var);
if (endpoint.registerFunction != null && endpoint.registerFunction.params.size() == 2) {
// Endpoint is already desugared. Fix this correctly.
args.add(0, epVariable);
}
final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, endpoint.registerFunction, args, symResolver);
if (endpoint.registerFunction != null && endpoint.registerFunction.params.size() != 2) {
iExpr.expr = ASTBuilderUtil.createVariableRef(epVariable.pos, epVariable.symbol);
}
expressionStmt.expr = iExpr;
return temp;
}
Aggregations