use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol in project ballerina by ballerina-lang.
the class SymbolResolver method getBinaryOpForNullChecks.
private BSymbol getBinaryOpForNullChecks(OperatorKind opKind, BType lhsType, BType rhsType) {
if (opKind != OperatorKind.EQUAL && opKind != OperatorKind.NOT_EQUAL) {
return symTable.notFoundSymbol;
}
int opcode = (opKind == OperatorKind.EQUAL) ? InstructionCodes.REQ_NULL : InstructionCodes.RNE_NULL;
if (lhsType.tag == TypeTags.NULL && (rhsType.tag == TypeTags.STRUCT || rhsType.tag == TypeTags.CONNECTOR || rhsType.tag == TypeTags.ENUM || rhsType.tag == TypeTags.INVOKABLE)) {
List<BType> paramTypes = Lists.of(lhsType, rhsType);
List<BType> retTypes = Lists.of(symTable.booleanType);
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
}
if ((lhsType.tag == TypeTags.STRUCT || lhsType.tag == TypeTags.CONNECTOR || lhsType.tag == TypeTags.ENUM || lhsType.tag == TypeTags.INVOKABLE) && rhsType.tag == TypeTags.NULL) {
List<BType> paramTypes = Lists.of(lhsType, rhsType);
List<BType> retTypes = Lists.of(symTable.booleanType);
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
}
if (lhsType.tag == TypeTags.ENUM && rhsType.tag == TypeTags.ENUM && lhsType == rhsType) {
opcode = (opKind == OperatorKind.EQUAL) ? InstructionCodes.REQ : InstructionCodes.RNE;
List<BType> paramTypes = Lists.of(lhsType, rhsType);
List<BType> retTypes = Lists.of(symTable.booleanType);
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
}
return symTable.notFoundSymbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol in project ballerina by ballerina-lang.
the class SemanticAnalyzer method getBinaryExpr.
private BLangExpression getBinaryExpr(BLangExpression lExpr, BLangExpression rExpr, OperatorKind opKind, BSymbol opSymbol) {
BLangBinaryExpr binaryExpressionNode = (BLangBinaryExpr) TreeBuilder.createBinaryExpressionNode();
binaryExpressionNode.lhsExpr = lExpr;
binaryExpressionNode.rhsExpr = rExpr;
binaryExpressionNode.pos = rExpr.pos;
binaryExpressionNode.opKind = opKind;
if (opSymbol != symTable.notFoundSymbol) {
binaryExpressionNode.type = opSymbol.type.getReturnTypes().get(0);
binaryExpressionNode.opSymbol = (BOperatorSymbol) opSymbol;
} else {
binaryExpressionNode.type = symTable.errType;
}
return binaryExpressionNode;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangBinaryExpr binaryExpr) {
BType lhsType = checkExpr(binaryExpr.lhsExpr, env).get(0);
BType rhsType = checkExpr(binaryExpr.rhsExpr, env).get(0);
// Set error type as the actual type.
BType actualType = symTable.errType;
// Look up operator symbol if both rhs and lhs types are error types
if (lhsType != symTable.errType && rhsType != symTable.errType) {
BSymbol opSymbol = symResolver.resolveBinaryOperator(binaryExpr.opKind, lhsType, rhsType);
if (opSymbol == symTable.notFoundSymbol) {
dlog.error(binaryExpr.pos, DiagnosticCode.BINARY_OP_INCOMPATIBLE_TYPES, binaryExpr.opKind, lhsType, rhsType);
} else {
binaryExpr.opSymbol = (BOperatorSymbol) opSymbol;
actualType = opSymbol.type.getReturnTypes().get(0);
}
}
resultTypes = types.checkTypes(binaryExpr, Lists.of(actualType), expTypes);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol in project ballerina by ballerina-lang.
the class ASTBuilderUtil method createUnaryExpr.
static BLangUnaryExpr createUnaryExpr(DiagnosticPos pos, BLangExpression expr, BType type, OperatorKind kind, BOperatorSymbol symbol) {
final BLangUnaryExpr unaryExpr = (BLangUnaryExpr) TreeBuilder.createUnaryExpressionNode();
unaryExpr.pos = pos;
unaryExpr.expr = expr;
unaryExpr.type = type;
unaryExpr.operator = kind;
unaryExpr.opSymbol = symbol;
return unaryExpr;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol in project ballerina by ballerina-lang.
the class Desugar method createPatternMatchBinaryExpr.
private BLangExpression createPatternMatchBinaryExpr(DiagnosticPos pos, BVarSymbol varSymbol, BType patternType) {
if (patternType == symTable.nullType) {
BLangSimpleVarRef varRef = ASTBuilderUtil.createVariableRef(pos, varSymbol);
BLangLiteral bLangLiteral = ASTBuilderUtil.createLiteral(pos, symTable.nullType, null);
return ASTBuilderUtil.createBinaryExpr(pos, varRef, bLangLiteral, symTable.booleanType, OperatorKind.EQUAL, (BOperatorSymbol) symResolver.resolveBinaryOperator(OperatorKind.EQUAL, symTable.anyType, symTable.nullType));
} else {
return createIsAssignableExpression(pos, varSymbol, patternType);
}
}
Aggregations