Search in sources :

Example 6 with BPackageSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

public void visit(BLangImportPackage importPkgNode) {
    BPackageSymbol pkgSymbol = importPkgNode.symbol;
    SymbolEnv pkgEnv = this.symTable.pkgEnvMap.get(pkgSymbol);
    if (pkgEnv == null) {
        return;
    }
    analyzeDef(pkgEnv.node, pkgEnv);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 7 with BPackageSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol 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)

Example 8 with BPackageSymbol

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

Example 9 with BPackageSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol in project ballerina by ballerina-lang.

the class TypeChecker method checkFunctionInvocationExpr.

private void checkFunctionInvocationExpr(BLangInvocation iExpr, BType bType) {
    Name funcName = names.fromString(Symbols.getAttachedFuncSymbolName(bType.toString(), iExpr.name.value));
    BPackageSymbol packageSymbol = (BPackageSymbol) bType.tsymbol.owner;
    BSymbol funcSymbol = symResolver.lookupMemberSymbol(iExpr.pos, packageSymbol.scope, this.env, funcName, SymTag.FUNCTION);
    if (funcSymbol == symTable.notFoundSymbol) {
        dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_FUNCTION, funcName);
        resultTypes = getListWithErrorTypes(expTypes.size());
        return;
    }
    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) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 10 with BPackageSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol in project ballerina by ballerina-lang.

the class CodeGenerator method genPackage.

private void genPackage(BPackageSymbol pkgSymbol) {
    // TODO First check whether this symbol is from a BALO file.
    SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgSymbol);
    genNode(pkgEnv.node, pkgEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Aggregations

BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)24 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)11 ArrayList (java.util.ArrayList)8 SymbolInfo (org.ballerinalang.langserver.completions.SymbolInfo)6 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)6 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)6 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)5 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 TokenStream (org.antlr.v4.runtime.TokenStream)3 PackageActionFunctionAndTypesFilter (org.ballerinalang.langserver.completions.util.filters.PackageActionFunctionAndTypesFilter)3 SymbolKind (org.ballerinalang.model.symbols.SymbolKind)3 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)3 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)3 Name (org.wso2.ballerinalang.compiler.util.Name)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Token (org.antlr.v4.runtime.Token)2 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)2