Search in sources :

Example 6 with BStructSymbol

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);
        }
    }
}
Also used : BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) Flag(org.ballerinalang.model.elements.Flag) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 7 with BStructSymbol

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);
    }
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)

Example 8 with BStructSymbol

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));
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)

Example 9 with BStructSymbol

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);
        }
    }
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)

Example 10 with BStructSymbol

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);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Aggregations

BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)17 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)7 BStructType (org.wso2.ballerinalang.compiler.semantics.model.types.BStructType)6 BAttachedFunction (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction)5 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)5 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)5 ArrayList (java.util.ArrayList)3 SymbolInfo (org.ballerinalang.langserver.completions.SymbolInfo)3 CompletionItem (org.eclipse.lsp4j.CompletionItem)3 List (java.util.List)2 BEndpointVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol)2 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)2 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)2 BJSONType (org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType)2 BStructField (org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField)2 BUnionType (org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType)2 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)2 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)2 Arrays (java.util.Arrays)1 Set (java.util.Set)1