use of org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr in project ballerina by ballerina-lang.
the class BLangPackageBuilder method createTypeConversionExpr.
public void createTypeConversionExpr(DiagnosticPos pos, Set<Whitespace> ws, boolean namedTransformer) {
BLangTypeConversionExpr typeConversionNode = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
typeConversionNode.pos = pos;
typeConversionNode.addWS(ws);
typeConversionNode.typeNode = (BLangType) typeNodeStack.pop();
typeConversionNode.expr = (BLangExpression) exprNodeStack.pop();
if (namedTransformer) {
typeConversionNode.transformerInvocation = (BLangInvocation) exprNodeStack.pop();
}
addExpressionNode(typeConversionNode);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr in project ballerina by ballerina-lang.
the class Desugar method addConversionExprIfRequired.
private BLangExpression addConversionExprIfRequired(BLangSimpleVarRef matchExprVarRef, BLangMatchStmtPatternClause patternClause) {
BType lhsType = patternClause.variable.type;
BType rhsType = matchExprVarRef.type;
if (types.isSameType(rhsType, lhsType)) {
return matchExprVarRef;
}
types.setImplicitCastExpr(matchExprVarRef, rhsType, lhsType);
if (matchExprVarRef.impConversionExpr != null) {
return matchExprVarRef;
}
BConversionOperatorSymbol conversionSymbol;
if (types.isValueType(lhsType) && !(rhsType.tag == TypeTags.JSON)) {
conversionSymbol = Symbols.createUnboxValueTypeOpSymbol(symTable.anyType, lhsType);
} else if (lhsType.tag == TypeTags.UNION || rhsType.tag == TypeTags.UNION) {
conversionSymbol = Symbols.createConversionOperatorSymbol(rhsType, lhsType, symTable.errStructType, false, true, InstructionCodes.NOP, null, null);
} else {
conversionSymbol = (BConversionOperatorSymbol) symResolver.resolveConversionOperator(rhsType, lhsType);
}
// Create a type cast expression
BLangTypeConversionExpr conversionExpr = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
conversionExpr.expr = matchExprVarRef;
conversionExpr.targetType = lhsType;
conversionExpr.conversionSymbol = conversionSymbol;
conversionExpr.type = lhsType;
return conversionExpr;
}
Aggregations