use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class TypeChecker method checkNamedTransformerInvocation.
private List<BType> checkNamedTransformerInvocation(BLangTypeConversionExpr conversionExpr, BType sourceType, BType targetType) {
List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
BLangInvocation transformerInvocation = conversionExpr.transformerInvocation;
BSymbol transformerSymbol = symResolver.lookupSymbolInPackage(transformerInvocation.pos, env, names.fromIdNode(transformerInvocation.pkgAlias), names.fromIdNode(transformerInvocation.name), SymTag.TRANSFORMER);
if (transformerSymbol == symTable.notFoundSymbol) {
dlog.error(conversionExpr.pos, DiagnosticCode.UNDEFINED_TRANSFORMER, transformerInvocation.name);
} else {
conversionExpr.conversionSymbol = (BConversionOperatorSymbol) (transformerInvocation.symbol = transformerSymbol);
// Check the transformer invocation. Expected type for the transformer is the target type
// of the cast conversion operator, but not the lhs type.
List<BType> prevExpType = expTypes;
expTypes = Lists.of(targetType);
checkInvocationParamAndReturnType(transformerInvocation);
expTypes = prevExpType;
if (transformerInvocation.type != symTable.errType) {
BInvokableType transformerSymType = (BInvokableType) transformerSymbol.type;
transformerInvocation.types = transformerSymType.retTypes;
actualTypes = getActualTypesOfConversionExpr(conversionExpr, targetType, sourceType, conversionExpr.conversionSymbol);
}
}
return actualTypes;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class TypeChecker method checkUnNamedTransformerInvocation.
private List<BType> checkUnNamedTransformerInvocation(BLangTypeConversionExpr conversionExpr, BType sourceType, BType targetType) {
List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
// Check whether a transformer is available for the two types
BSymbol symbol = symResolver.resolveTransformer(env, sourceType, targetType);
if (symbol == symTable.notFoundSymbol) {
// check whether a casting is possible, to provide user a hint.
BSymbol castSymbol = symResolver.resolveConversionOperator(sourceType, targetType);
if (castSymbol == symTable.notFoundSymbol) {
dlog.error(conversionExpr.pos, DiagnosticCode.INCOMPATIBLE_TYPES_CONVERSION, sourceType, targetType);
} else {
dlog.error(conversionExpr.pos, DiagnosticCode.INCOMPATIBLE_TYPES_CONVERSION_WITH_SUGGESTION, sourceType, targetType);
}
} else {
BTransformerSymbol transformerSymbol = (BTransformerSymbol) symbol;
conversionExpr.conversionSymbol = transformerSymbol;
if (conversionExpr.conversionSymbol.safe) {
((BInvokableType) transformerSymbol.type).retTypes.add(symTable.errStructType);
}
actualTypes = getActualTypesOfConversionExpr(conversionExpr, targetType, sourceType, transformerSymbol);
}
return actualTypes;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class SymbolTable method defineOperator.
private void defineOperator(Name name, List<BType> paramTypes, List<BType> retTypes, int opcode) {
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
BOperatorSymbol symbol = new BOperatorSymbol(name, rootPkgSymbol.pkgID, opType, rootPkgSymbol, opcode);
rootScope.define(name, symbol);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class SymbolTable method defineConversionOperator.
private void defineConversionOperator(BType sourceType, BType targetType, boolean implicit, boolean safe, int opcode) {
List<BType> paramTypes = Lists.of(sourceType, targetType);
List<BType> retTypes = new ArrayList<>(1);
if (safe) {
retTypes.add(targetType);
} else {
if (targetType.tag == TypeTags.UNION) {
BUnionType unionType = (BUnionType) targetType;
unionType.memberTypes.add(this.errStructType);
retTypes.add(targetType);
} else {
BUnionType unionType = new BUnionType(null, new HashSet<BType>(2) {
{
add(targetType);
add(errStructType);
}
}, false);
retTypes.add(unionType);
}
}
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
BConversionOperatorSymbol symbol = new BConversionOperatorSymbol(this.rootPkgSymbol.pkgID, opType, this.rootPkgSymbol, implicit, safe, opcode);
symbol.kind = SymbolKind.CONVERSION_OPERATOR;
rootScope.define(symbol.name, symbol);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class Symbols method createTypeofOperatorSymbol.
public static BOperatorSymbol createTypeofOperatorSymbol(BType exprType, Types types, SymbolTable symTable, Names names) {
List<BType> paramTypes = Lists.of(exprType);
List<BType> retTypes = Lists.of(symTable.typeDesc);
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
if (types.isValueType(exprType)) {
return new BOperatorSymbol(names.fromString(OperatorKind.TYPEOF.value()), symTable.rootPkgSymbol.pkgID, opType, symTable.rootPkgSymbol, InstructionCodes.TYPELOAD);
} else {
return new BOperatorSymbol(names.fromString(OperatorKind.TYPEOF.value()), symTable.rootPkgSymbol.pkgID, opType, symTable.rootPkgSymbol, InstructionCodes.TYPEOF);
}
}
Aggregations