use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol in project ballerina by ballerina-lang.
the class SymbolEnter method defineEndpointVarSymbol.
public BEndpointVarSymbol defineEndpointVarSymbol(DiagnosticPos pos, Set<Flag> flagSet, BType varType, Name varName, SymbolEnv env) {
// Create variable symbol
Scope enclScope = env.scope;
BEndpointVarSymbol varSymbol = new BEndpointVarSymbol(Flags.asMask(flagSet), varName, env.enclPkg.symbol.pkgID, varType, enclScope.owner);
// Find duplicates
if (!symResolver.checkForUniqueSymbol(pos, env, varSymbol, SymTag.VARIABLE_NAME)) {
varSymbol.type = symTable.errType;
}
enclScope.define(varSymbol.name, varSymbol);
return varSymbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol in project ballerina by ballerina-lang.
the class SemanticAnalyzer method defineResourceEndpoint.
private void defineResourceEndpoint(BLangResource resourceNode, SymbolEnv resourceEnv) {
if (!resourceNode.getParameters().isEmpty()) {
final BLangVariable variable = resourceNode.getParameters().get(0);
if (variable.type == symTable.endpointType) {
String actualVarName = variable.name.value.substring(1);
variable.name = new BLangIdentifier();
variable.name.value = actualVarName;
if (resourceEnv.enclService.endpointType != null) {
variable.type = resourceEnv.enclService.endpointType;
final BEndpointVarSymbol bEndpointVarSymbol = symbolEnter.defineEndpointVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
variable.symbol = bEndpointVarSymbol;
endpointSPIAnalyzer.populateEndpointSymbol((BStructSymbol) variable.type.tsymbol, bEndpointVarSymbol);
} else {
variable.type = symTable.errType;
variable.symbol = symbolEnter.defineVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
}
// Replace old symbol with new one.
resourceNode.symbol.params.remove(0);
resourceNode.symbol.params.add(0, variable.symbol);
((BInvokableType) resourceNode.symbol.type).paramTypes.remove(0);
((BInvokableType) resourceNode.symbol.type).paramTypes.add(0, variable.type);
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol in project ballerina by ballerina-lang.
the class SemanticAnalyzer method handleServiceEndpointBinds.
private void handleServiceEndpointBinds(BLangService serviceNode, BServiceSymbol serviceSymbol) {
for (BLangSimpleVarRef ep : serviceNode.boundEndpoints) {
typeChecker.checkExpr(ep, env);
if (ep.symbol == null || (ep.symbol.tag & SymTag.ENDPOINT) != SymTag.ENDPOINT) {
dlog.error(ep.pos, DiagnosticCode.ENDPOINT_INVALID_TYPE, ep.variableName);
continue;
}
final BEndpointVarSymbol epSym = (BEndpointVarSymbol) ep.symbol;
if ((epSym.tag & SymTag.ENDPOINT) == SymTag.ENDPOINT) {
if (epSym.registrable) {
serviceSymbol.boundEndpoints.add(epSym);
if (serviceNode.endpointType == null) {
serviceNode.endpointType = (BStructType) epSym.type;
serviceNode.endpointClientType = endpointSPIAnalyzer.getClientType((BStructSymbol) serviceNode.endpointType.tsymbol);
}
// TODO : Validate serviceType endpoint type with bind endpoint types.
} else {
dlog.error(ep.pos, DiagnosticCode.ENDPOINT_NOT_SUPPORT_REGISTRATION, epSym);
}
} else {
dlog.error(ep.pos, DiagnosticCode.ENDPOINT_INVALID_TYPE, epSym);
}
}
if (serviceNode.endpointType == null) {
dlog.error(serviceNode.pos, DiagnosticCode.SERVICE_INVALID_ENDPOINT_TYPE, serviceNode.name);
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol in project ballerina by ballerina-lang.
the class TypeChecker method checkActionInvocationExpr.
private void checkActionInvocationExpr(BLangInvocation iExpr, BType conType) {
List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
if (conType == symTable.errType || conType.tag != TypeTags.STRUCT || iExpr.expr.symbol.tag != SymTag.ENDPOINT) {
dlog.error(iExpr.pos, DiagnosticCode.INVALID_ACTION_INVOCATION);
resultTypes = actualTypes;
return;
}
final BEndpointVarSymbol epSymbol = (BEndpointVarSymbol) iExpr.expr.symbol;
if (!epSymbol.interactable) {
dlog.error(iExpr.pos, DiagnosticCode.ENDPOINT_NOT_SUPPORT_INTERACTIONS, epSymbol.name);
resultTypes = actualTypes;
return;
}
BSymbol conSymbol = epSymbol.clientSymbol;
if (conSymbol == null || conSymbol == symTable.notFoundSymbol || conSymbol == symTable.errSymbol || conSymbol.tag != SymTag.STRUCT) {
dlog.error(iExpr.pos, DiagnosticCode.INVALID_ACTION_INVOCATION);
resultTypes = actualTypes;
return;
}
Name actionName = names.fromIdNode(iExpr.name);
Name uniqueFuncName = names.fromString(Symbols.getAttachedFuncSymbolName(conSymbol.name.value, actionName.value));
BPackageSymbol packageSymbol = (BPackageSymbol) conSymbol.owner;
BSymbol actionSym = symResolver.lookupMemberSymbol(iExpr.pos, packageSymbol.scope, this.env, uniqueFuncName, SymTag.FUNCTION);
if (actionSym == symTable.errSymbol || actionSym == symTable.notFoundSymbol) {
dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_ACTION, actionName, epSymbol.name, conSymbol.type);
resultTypes = actualTypes;
return;
}
iExpr.symbol = actionSym;
checkInvocationParamAndReturnType(iExpr);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol in project ballerina by ballerina-lang.
the class EndpointSPIAnalyzer method populateEndpointSymbol.
public void populateEndpointSymbol(BStructSymbol structSymbol, BEndpointVarSymbol endpointVarSymbol) {
final Endpoint endpoint = validSPIs.get(structSymbol);
if (endpoint != null) {
final Endpoint endPoint = validSPIs.get(structSymbol);
endpointVarSymbol.initFunction = endPoint.initFunction;
endpointVarSymbol.interactable = endPoint.interactable;
endpointVarSymbol.getClientFunction = endPoint.getClientFunction;
endpointVarSymbol.clientSymbol = (BStructSymbol) endPoint.clientStruct.tsymbol;
endpointVarSymbol.startFunction = endPoint.startFunction;
endpointVarSymbol.stopFunction = endPoint.stopFunction;
endpointVarSymbol.registrable = endPoint.registrable;
endpointVarSymbol.registerFunction = endPoint.registerFunction;
}
}
Aggregations