Search in sources :

Example 6 with BTableType

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

the class Types method checkForeachTypes.

List<BType> checkForeachTypes(BLangNode collection, int variableSize) {
    BType collectionType = collection.type;
    List<BType> errorTypes;
    int maxSupportedTypes;
    switch(collectionType.tag) {
        case TypeTags.ARRAY:
            BArrayType bArrayType = (BArrayType) collectionType;
            if (variableSize == 1) {
                return Lists.of(bArrayType.eType);
            } else if (variableSize == 2) {
                return Lists.of(symTable.intType, bArrayType.eType);
            } else {
                maxSupportedTypes = 2;
                errorTypes = Lists.of(symTable.intType, bArrayType.eType);
            }
            break;
        case TypeTags.MAP:
            BMapType bMapType = (BMapType) collectionType;
            if (variableSize == 1) {
                return Lists.of(bMapType.constraint);
            } else if (variableSize == 2) {
                return Lists.of(symTable.stringType, bMapType.constraint);
            } else {
                maxSupportedTypes = 2;
                errorTypes = Lists.of(symTable.stringType, bMapType.constraint);
            }
            break;
        case TypeTags.JSON:
            if (variableSize == 1) {
                return Lists.of(symTable.jsonType);
            } else {
                maxSupportedTypes = 1;
                errorTypes = Lists.of(symTable.jsonType);
            }
            break;
        case TypeTags.XML:
            if (variableSize == 1) {
                return Lists.of(symTable.xmlType);
            } else if (variableSize == 2) {
                return Lists.of(symTable.intType, symTable.xmlType);
            } else {
                maxSupportedTypes = 2;
                errorTypes = Lists.of(symTable.intType, symTable.xmlType);
            }
            break;
        case TypeTags.TABLE:
            BTableType tableType = (BTableType) collectionType;
            if (variableSize == 1) {
                return Lists.of(tableType.constraint);
            } else {
                maxSupportedTypes = 1;
                errorTypes = Lists.of(tableType.constraint);
            }
            break;
        case TypeTags.ERROR:
            return Collections.nCopies(variableSize, symTable.errType);
        default:
            dlog.error(collection.pos, DiagnosticCode.ITERABLE_NOT_SUPPORTED_COLLECTION, collectionType);
            return Collections.nCopies(variableSize, symTable.errType);
    }
    dlog.error(collection.pos, DiagnosticCode.ITERABLE_TOO_MANY_VARIABLES, collectionType);
    errorTypes.addAll(Collections.nCopies(variableSize - maxSupportedTypes, symTable.errType));
    return errorTypes;
}
Also used : BMapType(org.wso2.ballerinalang.compiler.semantics.model.types.BMapType) BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BTableType(org.wso2.ballerinalang.compiler.semantics.model.types.BTableType)

Aggregations

BTableType (org.wso2.ballerinalang.compiler.semantics.model.types.BTableType)6 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)5 BMapType (org.wso2.ballerinalang.compiler.semantics.model.types.BMapType)4 BArrayType (org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType)3 BIntermediateCollectionType (org.wso2.ballerinalang.compiler.semantics.model.types.BIntermediateCollectionType)2 BJSONType (org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType)2 IterableKind (org.wso2.ballerinalang.compiler.semantics.model.iterable.IterableKind)1 Operation (org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation)1 BFutureType (org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType)1 BStreamType (org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType)1 BStructType (org.wso2.ballerinalang.compiler.semantics.model.types.BStructType)1 BTupleType (org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType)1 BXMLType (org.wso2.ballerinalang.compiler.semantics.model.types.BXMLType)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 BLangArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)1 BLangStructLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStructLiteral)1 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)1 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)1 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)1