Search in sources :

Example 11 with BLangTypeConversionExpr

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);
}
Also used : BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr)

Example 12 with BLangTypeConversionExpr

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;
}
Also used : BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BConversionOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol)

Aggregations

BLangTypeConversionExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr)7 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)6 BConversionOperatorSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol)5 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)4 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)2 BTransformerSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTransformerSymbol)1 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)1 BArrayType (org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType)1 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangIndexBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess)1 BLangTransformerInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangTransformerInvocation)1 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)1 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)1 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)1 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)1 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)1 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)1