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);
}
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;
}
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);
}
Aggregations