use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol 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.BStructSymbol 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.BStructSymbol in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
@Override
public void visit(BLangEndpoint endpointNode) {
endpointNode.annAttachments.forEach(annotationAttachment -> {
annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.ENDPOINT);
this.analyzeDef(annotationAttachment, env);
});
if (endpointNode.configurationExpr == null) {
return;
}
BType configType = symTable.errType;
if (endpointNode.symbol != null && endpointNode.symbol.type.tag == TypeTags.STRUCT) {
if (endpointNode.configurationExpr.getKind() == NodeKind.RECORD_LITERAL_EXPR) {
// Init expression.
configType = endpointSPIAnalyzer.getEndpointConfigType((BStructSymbol) endpointNode.symbol.type.tsymbol);
} else {
// assign Expression.
configType = endpointNode.symbol.type;
}
}
this.typeChecker.checkExpr(endpointNode.configurationExpr, env, Lists.of(configType));
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol in project ballerina by ballerina-lang.
the class SemanticAnalyzer method handleServiceTypeStruct.
private void handleServiceTypeStruct(BLangService serviceNode) {
if (serviceNode.serviceTypeStruct != null) {
final BType serviceStructType = symResolver.resolveTypeNode(serviceNode.serviceTypeStruct, env);
serviceNode.endpointType = endpointSPIAnalyzer.getEndpointTypeFromServiceType(serviceNode.serviceTypeStruct.pos, serviceStructType);
if (serviceNode.endpointType != null) {
serviceNode.endpointClientType = endpointSPIAnalyzer.getClientType((BStructSymbol) serviceNode.endpointType.tsymbol);
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol in project ballerina by ballerina-lang.
the class TypeChecker method checkFunctionInvocationExpr.
private void checkFunctionInvocationExpr(BLangInvocation iExpr, BStructType structType) {
String funcName = iExpr.name.value;
Name uniqueFuncName = names.fromString(Symbols.getAttachedFuncSymbolName(structType.tsymbol.name.value, funcName));
BPackageSymbol packageSymbol = (BPackageSymbol) structType.tsymbol.owner;
BSymbol funcSymbol = symResolver.lookupMemberSymbol(iExpr.pos, packageSymbol.scope, this.env, uniqueFuncName, SymTag.FUNCTION);
if (funcSymbol == symTable.notFoundSymbol) {
// Check functions defined within the struct.
Name functionName = names.fromString(Symbols.getAttachedFuncSymbolName(iExpr.expr.symbol.type.tsymbol.name.value, iExpr.name.value));
funcSymbol = symResolver.resolveStructField(iExpr.pos, env, functionName, iExpr.expr.symbol.type.tsymbol);
if (funcSymbol == symTable.notFoundSymbol) {
// Check, any function pointer in struct field with given name.
funcSymbol = symResolver.resolveStructField(iExpr.pos, env, names.fromIdNode(iExpr.name), iExpr.expr.symbol.type.tsymbol);
if (funcSymbol == symTable.notFoundSymbol || funcSymbol.type.tag != TypeTags.INVOKABLE) {
dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_FUNCTION_IN_STRUCT, funcName, structType);
resultTypes = getListWithErrorTypes(expTypes.size());
return;
}
if ((funcSymbol.flags & Flags.ATTACHED) != Flags.ATTACHED) {
iExpr.functionPointerInvocation = true;
}
}
} else {
// Attached function found
// Check for the explicit initializer function invocation
BStructSymbol.BAttachedFunction initializerFunc = ((BStructSymbol) structType.tsymbol).initializerFunc;
if (initializerFunc != null && initializerFunc.funcName.value.equals(funcName)) {
dlog.error(iExpr.pos, DiagnosticCode.STRUCT_INITIALIZER_INVOKED, structType.tsymbol.toString());
}
}
iExpr.symbol = funcSymbol;
checkInvocationParamAndReturnType(iExpr);
}
Aggregations