Search in sources :

Example 41 with BLangSimpleVarRef

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.

the class BLangPackageBuilder method createSimpleVariableReference.

public void createSimpleVariableReference(DiagnosticPos pos, Set<Whitespace> ws) {
    BLangNameReference nameReference = nameReferenceStack.pop();
    BLangSimpleVarRef varRef = (BLangSimpleVarRef) TreeBuilder.createSimpleVariableReferenceNode();
    varRef.pos = pos;
    varRef.addWS(ws);
    varRef.addWS(nameReference.ws);
    varRef.pkgAlias = (BLangIdentifier) nameReference.pkgAlias;
    varRef.variableName = (BLangIdentifier) nameReference.name;
    this.exprNodeStack.push(varRef);
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangNameReference(org.wso2.ballerinalang.compiler.tree.BLangNameReference)

Example 42 with BLangSimpleVarRef

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef 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)

Example 43 with BLangSimpleVarRef

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.

the class Desugar method visit.

@Override
public void visit(BLangRecordLiteral recordLiteral) {
    recordLiteral.keyValuePairs.forEach(keyValue -> {
        BLangExpression keyExpr = keyValue.key.expr;
        if (keyExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
            BLangSimpleVarRef varRef = (BLangSimpleVarRef) keyExpr;
            keyValue.key.expr = createStringLiteral(varRef.pos, varRef.variableName.value);
        } else {
            keyValue.key.expr = rewriteExpr(keyValue.key.expr);
        }
        keyValue.valueExpr = rewriteExpr(keyValue.valueExpr);
    });
    BLangExpression expr;
    if (recordLiteral.type.tag == TypeTags.STRUCT) {
        expr = new BLangStructLiteral(recordLiteral.keyValuePairs, recordLiteral.type);
    } else if (recordLiteral.type.tag == TypeTags.MAP) {
        expr = new BLangMapLiteral(recordLiteral.keyValuePairs, recordLiteral.type);
    } else if (recordLiteral.type.tag == TypeTags.TABLE) {
        expr = new BLangTableLiteral(recordLiteral.type);
    } else if (recordLiteral.type.tag == TypeTags.STREAM) {
        expr = new BLangStreamLiteral(recordLiteral.type, recordLiteral.name);
    } else {
        expr = new BLangJSONLiteral(recordLiteral.keyValuePairs, recordLiteral.type);
    }
    result = rewriteExpr(expr);
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangStructLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStructLiteral) BLangMapLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangMapLiteral) BLangStreamLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStreamLiteral) BLangJSONLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangJSONLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangTableLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangTableLiteral)

Aggregations

BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)36 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)11 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)9 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)8 Name (org.wso2.ballerinalang.compiler.util.Name)8 ArrayList (java.util.ArrayList)7 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)6 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)5 BLangAnnotationAttachmentPoint (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)4 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)4 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)3 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)3 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)3 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)3 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)3 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)2 BJSONType (org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType)2 BLangFieldBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess)2 BLangJSONLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangJSONLiteral)2 BLangMapLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangMapLiteral)2