Search in sources :

Example 11 with BSymbol

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

the class SymbolResolver method getBinaryOpForNullChecks.

private BSymbol getBinaryOpForNullChecks(OperatorKind opKind, BType lhsType, BType rhsType) {
    if (opKind != OperatorKind.EQUAL && opKind != OperatorKind.NOT_EQUAL) {
        return symTable.notFoundSymbol;
    }
    int opcode = (opKind == OperatorKind.EQUAL) ? InstructionCodes.REQ_NULL : InstructionCodes.RNE_NULL;
    if (lhsType.tag == TypeTags.NULL && (rhsType.tag == TypeTags.STRUCT || rhsType.tag == TypeTags.CONNECTOR || rhsType.tag == TypeTags.ENUM || rhsType.tag == TypeTags.INVOKABLE)) {
        List<BType> paramTypes = Lists.of(lhsType, rhsType);
        List<BType> retTypes = Lists.of(symTable.booleanType);
        BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
        return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
    }
    if ((lhsType.tag == TypeTags.STRUCT || lhsType.tag == TypeTags.CONNECTOR || lhsType.tag == TypeTags.ENUM || lhsType.tag == TypeTags.INVOKABLE) && rhsType.tag == TypeTags.NULL) {
        List<BType> paramTypes = Lists.of(lhsType, rhsType);
        List<BType> retTypes = Lists.of(symTable.booleanType);
        BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
        return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
    }
    if (lhsType.tag == TypeTags.ENUM && rhsType.tag == TypeTags.ENUM && lhsType == rhsType) {
        opcode = (opKind == OperatorKind.EQUAL) ? InstructionCodes.REQ : InstructionCodes.RNE;
        List<BType> paramTypes = Lists.of(lhsType, rhsType);
        List<BType> retTypes = Lists.of(symTable.booleanType);
        BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
        return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
    }
    return symTable.notFoundSymbol;
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol)

Example 12 with BSymbol

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

the class SymbolResolver method visit.

public void visit(BLangUserDefinedType userDefinedTypeNode) {
    // 1) Resolve the package scope using the package alias.
    // If the package alias is not empty or null, then find the package scope,
    // if not use the current package scope.
    // 2) lookup the typename in the package scope returned from step 1.
    // 3) If the symbol is not found, then lookup in the root scope. e.g. for types such as 'error'
    BSymbol pkgSymbol = resolvePkgSymbol(userDefinedTypeNode.pos, this.env, names.fromIdNode(userDefinedTypeNode.pkgAlias));
    if (pkgSymbol == symTable.notFoundSymbol) {
        resultType = symTable.errType;
        return;
    }
    Name typeName = names.fromIdNode(userDefinedTypeNode.typeName);
    BSymbol symbol = symTable.notFoundSymbol;
    // Only valued types and ANNOTATION type allowed.
    if (env.scope.owner.tag == SymTag.ANNOTATION) {
        symbol = lookupMemberSymbol(userDefinedTypeNode.pos, pkgSymbol.scope, this.env, typeName, SymTag.ANNOTATION);
    }
    // 3) Lookup the current package scope.
    if (symbol == symTable.notFoundSymbol) {
        symbol = lookupMemberSymbol(userDefinedTypeNode.pos, pkgSymbol.scope, this.env, typeName, SymTag.VARIABLE_NAME);
    }
    if (symbol == symTable.notFoundSymbol) {
        // 4) Lookup the root scope for types such as 'error'
        symbol = lookupMemberSymbol(userDefinedTypeNode.pos, symTable.rootScope, this.env, typeName, SymTag.VARIABLE_NAME);
    }
    if (symbol == symTable.notFoundSymbol) {
        dlog.error(userDefinedTypeNode.pos, diagCode, typeName);
        resultType = symTable.errType;
        return;
    }
    if (symbol.kind == SymbolKind.CONNECTOR) {
        userDefinedTypeNode.flagSet = EnumSet.of(Flag.CONNECTOR);
    }
    resultType = symbol.type;
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 13 with BSymbol

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

the class SymbolResolver method resolveOperator.

private BSymbol resolveOperator(ScopeEntry entry, List<BType> types) {
    BSymbol foundSymbol = symTable.notFoundSymbol;
    while (entry != NOT_FOUND_ENTRY) {
        BInvokableType opType = (BInvokableType) entry.symbol.type;
        if (types.size() == opType.paramTypes.size()) {
            boolean match = true;
            for (int i = 0; i < types.size(); i++) {
                if (types.get(i).tag != opType.paramTypes.get(i).tag) {
                    match = false;
                }
            }
            if (match) {
                foundSymbol = entry.symbol;
                break;
            }
        }
        entry = entry.next;
    }
    return foundSymbol;
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)

Example 14 with BSymbol

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

the class TaintAnalyzer method visit.

public void visit(BLangConnector connectorNode) {
    BSymbol connectorSymbol = connectorNode.symbol;
    SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorSymbol.scope, env);
    attachTaintTableBasedOnAnnotations(connectorNode);
    connectorNode.varDefs.forEach(var -> var.accept(this));
    analyzeNode(connectorNode.initFunction, connectorEnv);
    analyzeNode(connectorNode.initAction, connectorEnv);
    connectorNode.actions.forEach(action -> analyzeNode(action, connectorEnv));
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 15 with BSymbol

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

the class CodeAnalyzer method visit.

public void visit(BLangInvocation invocationExpr) {
    analyzeExpr(invocationExpr.expr);
    analyzeExprs(invocationExpr.requiredArgs);
    analyzeExprs(invocationExpr.namedArgs);
    analyzeExprs(invocationExpr.restArgs);
    checkDuplicateNamedArgs(invocationExpr.namedArgs);
    // Null check is to ignore Negative path where symbol does not get resolved at TypeChecker.
    if ((invocationExpr.symbol != null) && invocationExpr.symbol.kind == SymbolKind.FUNCTION) {
        BSymbol funcSymbol = invocationExpr.symbol;
        if (Symbols.isFlagOn(funcSymbol.flags, Flags.DEPRECATED)) {
            dlog.warning(invocationExpr.pos, DiagnosticCode.USAGE_OF_DEPRECATED_FUNCTION, names.fromIdNode(invocationExpr.name));
        }
    }
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)

Aggregations

BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)78 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)29 Name (org.wso2.ballerinalang.compiler.util.Name)23 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)19 ArrayList (java.util.ArrayList)16 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)14 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)13 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)13 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)12 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)11 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)11 List (java.util.List)10 BLangAnnotationAttachmentPoint (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)10 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)10 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)10 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)10 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)10 Collectors (java.util.stream.Collectors)9 Arrays (java.util.Arrays)8 Collections (java.util.Collections)7