Search in sources :

Example 46 with BType

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

the class Types method checkConnectorEquivalency.

public boolean checkConnectorEquivalency(BType actualType, BType expType) {
    if (actualType.tag != TypeTags.CONNECTOR || expType.tag != TypeTags.CONNECTOR) {
        return false;
    }
    if (isSameType(actualType, expType)) {
        return true;
    }
    BConnectorType expConnectorType = (BConnectorType) expType;
    BConnectorType actualConnectorType = (BConnectorType) actualType;
    // take actions in connectors
    List<BInvokableSymbol> expActions = symResolver.getConnectorActionSymbols(expConnectorType.tsymbol.scope);
    List<BInvokableSymbol> actActions = symResolver.getConnectorActionSymbols(actualConnectorType.tsymbol.scope);
    if (expActions.isEmpty() && actActions.isEmpty()) {
        return true;
    }
    if (expActions.size() != actActions.size()) {
        return false;
    }
    // check every action signatures are matching or not
    for (BInvokableSymbol expAction : expActions) {
        if (actActions.stream().filter(v -> checkActionTypeEquality(expAction, v)).collect(Collectors.toList()).size() != 1) {
            return false;
        }
    }
    return true;
}
Also used : BStructField(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField) 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) BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr) BAttachedFunction(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction) BStreamType(org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType) BBuiltInRefType(org.wso2.ballerinalang.compiler.semantics.model.types.BBuiltInRefType) Lists(org.wso2.ballerinalang.util.Lists) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) ArrayList(java.util.ArrayList) BXMLType(org.wso2.ballerinalang.compiler.semantics.model.types.BXMLType) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) HashSet(java.util.HashSet) Flags(org.wso2.ballerinalang.util.Flags) TreeBuilder(org.ballerinalang.model.TreeBuilder) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) Names(org.wso2.ballerinalang.compiler.util.Names) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BErrorType(org.wso2.ballerinalang.compiler.semantics.model.types.BErrorType) 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) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType) BLangDiagnosticLog(org.wso2.ballerinalang.compiler.util.diagnotic.BLangDiagnosticLog) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BConversionOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BJSONType(org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType) Set(java.util.Set) BTypeVisitor(org.wso2.ballerinalang.compiler.semantics.model.types.BTypeVisitor) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) Collectors(java.util.stream.Collectors) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) List(java.util.List) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode) InstructionCodes(org.wso2.ballerinalang.programfile.InstructionCodes) BAnyType(org.wso2.ballerinalang.compiler.semantics.model.types.BAnyType) BTableType(org.wso2.ballerinalang.compiler.semantics.model.types.BTableType) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) Collections(java.util.Collections) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)

Example 47 with BType

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

the class Types method isAssignableToUnionType.

private boolean isAssignableToUnionType(BType source, BType target) {
    Set<BType> sourceTypes = new HashSet<>();
    Set<BType> targetTypes = new HashSet<>();
    if (source.tag == TypeTags.UNION) {
        BUnionType sourceUnionType = (BUnionType) source;
        sourceTypes.addAll(sourceUnionType.memberTypes);
    } else {
        sourceTypes.add(source);
    }
    if (target.tag == TypeTags.UNION) {
        BUnionType targetUnionType = (BUnionType) target;
        targetTypes.addAll(targetUnionType.memberTypes);
    } else {
        targetTypes.add(target);
    }
    boolean notAssignable = sourceTypes.stream().map(s -> targetTypes.stream().anyMatch(t -> isAssignable(s, t))).anyMatch(assignable -> !assignable);
    return !notAssignable;
}
Also used : BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BStructField(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField) 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) BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr) BAttachedFunction(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction) BStreamType(org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType) BBuiltInRefType(org.wso2.ballerinalang.compiler.semantics.model.types.BBuiltInRefType) Lists(org.wso2.ballerinalang.util.Lists) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) ArrayList(java.util.ArrayList) BXMLType(org.wso2.ballerinalang.compiler.semantics.model.types.BXMLType) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) HashSet(java.util.HashSet) Flags(org.wso2.ballerinalang.util.Flags) TreeBuilder(org.ballerinalang.model.TreeBuilder) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) Names(org.wso2.ballerinalang.compiler.util.Names) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BErrorType(org.wso2.ballerinalang.compiler.semantics.model.types.BErrorType) 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) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType) BLangDiagnosticLog(org.wso2.ballerinalang.compiler.util.diagnotic.BLangDiagnosticLog) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BConversionOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BJSONType(org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType) Set(java.util.Set) BTypeVisitor(org.wso2.ballerinalang.compiler.semantics.model.types.BTypeVisitor) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) Collectors(java.util.stream.Collectors) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) List(java.util.List) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode) InstructionCodes(org.wso2.ballerinalang.programfile.InstructionCodes) BAnyType(org.wso2.ballerinalang.compiler.semantics.model.types.BAnyType) BTableType(org.wso2.ballerinalang.compiler.semantics.model.types.BTableType) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) Collections(java.util.Collections) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) HashSet(java.util.HashSet)

Example 48 with BType

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

the class Symbols method createConversionOperatorSymbol.

public static BConversionOperatorSymbol createConversionOperatorSymbol(final BType sourceType, final BType targetType, final BType errorType, boolean implicit, boolean safe, int opcode, PackageID pkgID, BSymbol owner) {
    List<BType> paramTypes = Lists.of(sourceType, targetType);
    List<BType> retTypes = new ArrayList<>(1);
    if (safe) {
        retTypes.add(targetType);
    } else if (targetType.tag == TypeTags.UNION && targetType instanceof BUnionType) {
        BUnionType unionType = (BUnionType) targetType;
        unionType.memberTypes.add(errorType);
        retTypes.add(unionType);
    } else {
        Set<BType> memberTypes = new HashSet<>(2);
        memberTypes.add(targetType);
        memberTypes.add(errorType);
        BUnionType unionType = new BUnionType(null, memberTypes, false);
        retTypes.add(unionType);
    }
    BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
    BConversionOperatorSymbol symbol = new BConversionOperatorSymbol(pkgID, opType, owner, implicit, safe, opcode);
    symbol.kind = SymbolKind.CONVERSION_OPERATOR;
    return symbol;
}
Also used : BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) Set(java.util.Set) HashSet(java.util.HashSet) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)

Example 49 with BType

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

the class CodeGenerator method createActionInfoEntry.

private void createActionInfoEntry(BLangAction actionNode, ConnectorInfo connectorInfo) {
    BInvokableSymbol actionSymbol = actionNode.symbol;
    BInvokableType actionType = (BInvokableType) actionSymbol.type;
    // Add action name as an UTFCPEntry to the constant pool
    int actionNameCPIndex = addUTF8CPEntry(currentPkgInfo, actionNode.name.value);
    ActionInfo actionInfo = new ActionInfo(currentPackageRefCPIndex, actionNameCPIndex);
    actionInfo.paramTypes = actionType.paramTypes.toArray(new BType[0]);
    actionInfo.retParamTypes = actionType.retTypes.toArray(new BType[0]);
    actionInfo.flags = actionSymbol.flags;
    // setParameterNames(actionNode, actionInfo);
    actionInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(actionInfo.paramTypes, actionInfo.retParamTypes));
    // Add worker info
    this.addWorkerInfoEntries(actionInfo, actionNode.getWorkers());
    // Add parameter default value info
    addParameterDefaultValues(actionNode, actionInfo);
    // Add action info to the connector info
    connectorInfo.actionInfoMap.put(actionNode.name.getValue(), actionInfo);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) ActionInfo(org.wso2.ballerinalang.programfile.ActionInfo) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 50 with BType

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

the class CodeGenerator method createFunctionInfoEntry.

/**
 * Creates a {@code FunctionInfo} from the given function node in AST.
 *
 * @param funcNode function node in AST
 */
private void createFunctionInfoEntry(BLangFunction funcNode) {
    BInvokableSymbol funcSymbol = funcNode.symbol;
    BInvokableType funcType = (BInvokableType) funcSymbol.type;
    // Add function name as an UTFCPEntry to the constant pool
    int funcNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, funcNode.name.value);
    FunctionInfo funcInfo = new FunctionInfo(currentPackageRefCPIndex, funcNameCPIndex);
    funcInfo.paramTypes = funcType.paramTypes.toArray(new BType[0]);
    funcInfo.retParamTypes = funcType.retTypes.toArray(new BType[0]);
    funcInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(funcInfo.paramTypes, funcInfo.retParamTypes));
    funcInfo.flags = funcSymbol.flags;
    if (funcNode.receiver != null) {
        funcInfo.attachedToTypeCPIndex = getTypeCPIndex(funcNode.receiver.type).value;
    }
    this.addWorkerInfoEntries(funcInfo, funcNode.getWorkers());
    // Add parameter default value info
    addParameterDefaultValues(funcNode, funcInfo);
    this.currentPkgInfo.functionInfoMap.put(funcSymbol.name.value, funcInfo);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) AttachedFunctionInfo(org.wso2.ballerinalang.programfile.AttachedFunctionInfo) FunctionInfo(org.wso2.ballerinalang.programfile.FunctionInfo) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

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