Search in sources :

Example 1 with BLangConstrainedType

use of org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType in project ballerina by ballerina-lang.

the class SymbolResolver method visit.

public void visit(BLangConstrainedType constrainedTypeNode) {
    BType type = resolveTypeNode(constrainedTypeNode.type, env);
    BType constraintType = resolveTypeNode(constrainedTypeNode.constraint, env);
    if (type.tag == TypeTags.TABLE) {
        resultType = new BTableType(TypeTags.TABLE, constraintType, type.tsymbol);
    } else if (type.tag == TypeTags.STREAM) {
        resultType = new BStreamType(TypeTags.STREAM, constraintType, type.tsymbol);
    } else if (type.tag == TypeTags.FUTURE) {
        resultType = new BFutureType(TypeTags.FUTURE, constraintType, type.tsymbol);
    } else if (type.tag == TypeTags.MAP) {
        resultType = new BMapType(TypeTags.MAP, constraintType, type.tsymbol);
    } else {
        if (!types.checkStructToJSONCompatibility(constraintType) && constraintType != symTable.errType) {
            dlog.error(constrainedTypeNode.pos, DiagnosticCode.INCOMPATIBLE_TYPE_CONSTRAINT, type, constraintType);
            resultType = symTable.errType;
            return;
        }
        resultType = new BJSONType(TypeTags.JSON, constraintType, type.tsymbol);
    }
}
Also used : BMapType(org.wso2.ballerinalang.compiler.semantics.model.types.BMapType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BJSONType(org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType) BTableType(org.wso2.ballerinalang.compiler.semantics.model.types.BTableType) BStreamType(org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType) BFutureType(org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType)

Example 2 with BLangConstrainedType

use of org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addConstraintType.

public void addConstraintType(DiagnosticPos pos, Set<Whitespace> ws, String typeName) {
    BLangNameReference nameReference = nameReferenceStack.pop();
    BLangUserDefinedType constraintType = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
    constraintType.pos = pos;
    constraintType.pkgAlias = (BLangIdentifier) nameReference.pkgAlias;
    constraintType.typeName = (BLangIdentifier) nameReference.name;
    constraintType.addWS(nameReference.ws);
    Set<Whitespace> refTypeWS = removeNthFromLast(ws, 2);
    BLangBuiltInRefTypeNode refType = (BLangBuiltInRefTypeNode) TreeBuilder.createBuiltInReferenceTypeNode();
    refType.typeKind = TreeUtils.stringToTypeKind(typeName);
    refType.pos = pos;
    refType.addWS(refTypeWS);
    BLangConstrainedType constrainedType = (BLangConstrainedType) TreeBuilder.createConstrainedTypeNode();
    constrainedType.type = refType;
    constrainedType.constraint = constraintType;
    constrainedType.pos = pos;
    constrainedType.addWS(ws);
    addType(constrainedType);
}
Also used : BLangConstrainedType(org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType) BLangNameReference(org.wso2.ballerinalang.compiler.tree.BLangNameReference) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) Whitespace(org.ballerinalang.model.Whitespace)

Example 3 with BLangConstrainedType

use of org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addConstraintTypeWithTypeName.

public void addConstraintTypeWithTypeName(DiagnosticPos pos, Set<Whitespace> ws, String typeName) {
    Set<Whitespace> refTypeWS = removeNthFromLast(ws, 2);
    BLangBuiltInRefTypeNode refType = (BLangBuiltInRefTypeNode) TreeBuilder.createBuiltInReferenceTypeNode();
    refType.typeKind = TreeUtils.stringToTypeKind(typeName);
    refType.pos = pos;
    refType.addWS(refTypeWS);
    BLangConstrainedType constrainedType = (BLangConstrainedType) TreeBuilder.createConstrainedTypeNode();
    constrainedType.type = refType;
    constrainedType.constraint = (BLangType) this.typeNodeStack.pop();
    constrainedType.pos = pos;
    constrainedType.addWS(ws);
    addType(constrainedType);
}
Also used : BLangConstrainedType(org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) Whitespace(org.ballerinalang.model.Whitespace)

Aggregations

Whitespace (org.ballerinalang.model.Whitespace)2 BLangBuiltInRefTypeNode (org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode)2 BLangConstrainedType (org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType)2 BFutureType (org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType)1 BJSONType (org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType)1 BMapType (org.wso2.ballerinalang.compiler.semantics.model.types.BMapType)1 BStreamType (org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType)1 BTableType (org.wso2.ballerinalang.compiler.semantics.model.types.BTableType)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)1 BLangUserDefinedType (org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)1