Search in sources :

Example 71 with BType

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

the class SymbolEnter method defineVarSymbol.

public BVarSymbol defineVarSymbol(DiagnosticPos pos, Set<Flag> flagSet, BType varType, Name varName, SymbolEnv env) {
    // Create variable symbol
    Scope enclScope = env.scope;
    BVarSymbol varSymbol;
    if (varType.tag == TypeTags.INVOKABLE) {
        varSymbol = new BInvokableSymbol(SymTag.VARIABLE, Flags.asMask(flagSet), varName, env.enclPkg.symbol.pkgID, varType, enclScope.owner);
    } else {
        varSymbol = new BVarSymbol(Flags.asMask(flagSet), varName, env.enclPkg.symbol.pkgID, varType, enclScope.owner);
    }
    // Find duplicates
    if (!symResolver.checkForUniqueSymbol(pos, env, varSymbol, SymTag.VARIABLE_NAME)) {
        varSymbol.type = symTable.errType;
    }
    enclScope.define(varSymbol.name, varSymbol);
    return varSymbol;
}
Also used : Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 72 with BType

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

the class SymbolEnter method validateFuncReceiver.

private boolean validateFuncReceiver(BLangFunction funcNode) {
    if (funcNode.receiver == null) {
        return true;
    }
    BType varType = symResolver.resolveTypeNode(funcNode.receiver.typeNode, env);
    funcNode.receiver.type = varType;
    if (varType.tag == TypeTags.ERROR) {
        return true;
    }
    if (varType.tag != TypeTags.BOOLEAN && varType.tag != TypeTags.STRING && varType.tag != TypeTags.INT && varType.tag != TypeTags.FLOAT && varType.tag != TypeTags.BLOB && varType.tag != TypeTags.JSON && varType.tag != TypeTags.XML && varType.tag != TypeTags.MAP && varType.tag != TypeTags.TABLE && varType.tag != TypeTags.STREAM && varType.tag != TypeTags.FUTURE && varType.tag != TypeTags.STRUCT) {
        dlog.error(funcNode.receiver.pos, DiagnosticCode.FUNC_DEFINED_ON_NOT_SUPPORTED_TYPE, funcNode.name.value, varType.toString());
        return false;
    }
    if (!this.env.enclPkg.symbol.pkgID.equals(varType.tsymbol.pkgID)) {
        dlog.error(funcNode.receiver.pos, DiagnosticCode.FUNC_DEFINED_ON_NON_LOCAL_TYPE, funcNode.name.value, varType.toString());
        return false;
    }
    return true;
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType)

Example 73 with BType

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

the class SymbolEnter method validateTransformerMappingTypes.

private void validateTransformerMappingTypes(BLangTransformer transformerNode) {
    BType varType = symResolver.resolveTypeNode(transformerNode.source.typeNode, env);
    transformerNode.source.type = varType;
    transformerNode.retParams.forEach(returnParams -> {
        BType targetType = symResolver.resolveTypeNode(returnParams.typeNode, env);
        returnParams.type = targetType;
    });
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType)

Example 74 with BType

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

the class SymbolEnter method resolveAnnotationAttributeTypes.

@Deprecated
private void resolveAnnotationAttributeTypes(List<BLangAnnotation> annotations, SymbolEnv pkgEnv) {
    annotations.forEach(annotation -> {
        annotation.attributes.forEach(attribute -> {
            SymbolEnv annotationEnv = SymbolEnv.createAnnotationEnv(annotation, annotation.symbol.scope, pkgEnv);
            BType actualType = this.symResolver.resolveTypeNode(attribute.typeNode, annotationEnv);
            attribute.symbol.type = actualType;
        });
    });
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 75 with BType

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

the class SymbolEnter method visit.

public void visit(BLangAnnotation annotationNode) {
    BSymbol annotationSymbol = Symbols.createAnnotationSymbol(Flags.asMask(annotationNode.flagSet), names.fromIdNode(annotationNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
    annotationSymbol.type = new BAnnotationType((BAnnotationSymbol) annotationSymbol);
    annotationNode.attachmentPoints.forEach(point -> ((BAnnotationSymbol) annotationSymbol).attachmentPoints.add(point));
    annotationNode.symbol = annotationSymbol;
    defineSymbol(annotationNode.pos, annotationSymbol);
    SymbolEnv annotationEnv = SymbolEnv.createAnnotationEnv(annotationNode, annotationSymbol.scope, env);
    annotationNode.attributes.forEach(att -> this.defineNode(att, annotationEnv));
    if (annotationNode.typeNode != null) {
        BType structType = this.symResolver.resolveTypeNode(annotationNode.typeNode, annotationEnv);
        ((BAnnotationSymbol) annotationSymbol).attachedType = structType.tsymbol;
    }
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BAnnotationType(org.wso2.ballerinalang.compiler.semantics.model.types.BAnnotationType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BAnnotationSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol)

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