Search in sources :

Example 11 with BType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.

the class SymbolResolver method visit.

public void visit(BLangTupleTypeNode tupleTypeNode) {
    List<BType> memberTypes = tupleTypeNode.memberTypeNodes.stream().map(memTypeNode -> resolveTypeNode(memTypeNode, env)).collect(Collectors.toList());
    resultType = new BTupleType(memberTypes);
}
Also used : BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType) BMapType(org.wso2.ballerinalang.compiler.semantics.model.types.BMapType) BLangTupleTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangTupleTypeNode) Lists(org.wso2.ballerinalang.util.Lists) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BLangValueType(org.wso2.ballerinalang.compiler.tree.types.BLangValueType) OperatorKind(org.ballerinalang.model.tree.OperatorKind) Flag(org.ballerinalang.model.elements.Flag) Map(java.util.Map) SymbolKind(org.ballerinalang.model.symbols.SymbolKind) BOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol) Names(org.wso2.ballerinalang.compiler.util.Names) EnumSet(java.util.EnumSet) BLangDiagnosticLog(org.wso2.ballerinalang.compiler.util.diagnotic.BLangDiagnosticLog) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BLangArrayType(org.wso2.ballerinalang.compiler.tree.types.BLangArrayType) BLangUnionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangUnionTypeNode) TypeKind(org.ballerinalang.model.types.TypeKind) BConversionOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) NOT_FOUND_ENTRY(org.wso2.ballerinalang.compiler.semantics.model.Scope.NOT_FOUND_ENTRY) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) Stream(java.util.stream.Stream) InstructionCodes(org.wso2.ballerinalang.programfile.InstructionCodes) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BStreamType(org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType) HashMap(java.util.HashMap) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) ArrayList(java.util.ArrayList) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) BLangConstrainedType(org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BFutureType(org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BJSONType(org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangFunctionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangFunctionTypeNode) Name(org.wso2.ballerinalang.compiler.util.Name) ScopeEntry(org.wso2.ballerinalang.compiler.semantics.model.Scope.ScopeEntry) SymTag(org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode) BTableType(org.wso2.ballerinalang.compiler.semantics.model.types.BTableType) BLangType(org.wso2.ballerinalang.compiler.tree.types.BLangType) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType)

Example 12 with BType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BType 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 13 with BType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.

the class SymbolResolver method visit.

public void visit(BLangUnionTypeNode unionTypeNode) {
    Set<BType> memberTypes = unionTypeNode.memberTypeNodes.stream().map(memTypeNode -> resolveTypeNode(memTypeNode, env)).flatMap(memBType -> memBType.tag == TypeTags.UNION ? ((BUnionType) memBType).memberTypes.stream() : Stream.of(memBType)).collect(Collectors.toSet());
    resultType = new BUnionType(null, memberTypes, memberTypes.contains(symTable.nullType));
}
Also used : BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType) BMapType(org.wso2.ballerinalang.compiler.semantics.model.types.BMapType) BLangTupleTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangTupleTypeNode) Lists(org.wso2.ballerinalang.util.Lists) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BLangValueType(org.wso2.ballerinalang.compiler.tree.types.BLangValueType) OperatorKind(org.ballerinalang.model.tree.OperatorKind) Flag(org.ballerinalang.model.elements.Flag) Map(java.util.Map) SymbolKind(org.ballerinalang.model.symbols.SymbolKind) BOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol) Names(org.wso2.ballerinalang.compiler.util.Names) EnumSet(java.util.EnumSet) BLangDiagnosticLog(org.wso2.ballerinalang.compiler.util.diagnotic.BLangDiagnosticLog) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BLangArrayType(org.wso2.ballerinalang.compiler.tree.types.BLangArrayType) BLangUnionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangUnionTypeNode) TypeKind(org.ballerinalang.model.types.TypeKind) BConversionOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) NOT_FOUND_ENTRY(org.wso2.ballerinalang.compiler.semantics.model.Scope.NOT_FOUND_ENTRY) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) Stream(java.util.stream.Stream) InstructionCodes(org.wso2.ballerinalang.programfile.InstructionCodes) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BStreamType(org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType) HashMap(java.util.HashMap) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) ArrayList(java.util.ArrayList) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) BLangConstrainedType(org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BFutureType(org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BJSONType(org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangFunctionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangFunctionTypeNode) Name(org.wso2.ballerinalang.compiler.util.Name) ScopeEntry(org.wso2.ballerinalang.compiler.semantics.model.Scope.ScopeEntry) SymTag(org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode) BTableType(org.wso2.ballerinalang.compiler.semantics.model.types.BTableType) BLangType(org.wso2.ballerinalang.compiler.tree.types.BLangType) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType)

Example 14 with BType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BType 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 15 with BType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.

the class TaintAnalyzer method isEntryPoint.

// Private methods related to invokable node analysis and taint-table generation.
private boolean isEntryPoint(BLangFunction funcNode) {
    // Service resources are handled through BLangResource visitor.
    boolean isMainFunction = false;
    if (funcNode.name.value.equals(MAIN_FUNCTION_NAME) && funcNode.symbol.params.size() == 1 && funcNode.symbol.retParams.size() == 0) {
        BType paramType = funcNode.symbol.params.get(0).type;
        BArrayType arrayType = (BArrayType) paramType;
        if (paramType.tag == TypeTags.ARRAY && arrayType.eType.tag == TypeTags.STRING) {
            isMainFunction = true;
        }
    }
    return isMainFunction;
}
Also used : BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType)

Aggregations

BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)97 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)34 ArrayList (java.util.ArrayList)30 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)30 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)25 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)23 Name (org.wso2.ballerinalang.compiler.util.Name)20 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)18 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)17 BArrayType (org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType)17 BUnionType (org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType)17 List (java.util.List)16 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)16 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)16 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)15 Collectors (java.util.stream.Collectors)14 BConversionOperatorSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol)13 BStructType (org.wso2.ballerinalang.compiler.semantics.model.types.BStructType)13 Set (java.util.Set)12 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)12