Search in sources :

Example 11 with BOperatorSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol in project ballerina by ballerina-lang.

the class TypeChecker method getBinaryAddExpr.

private BLangExpression getBinaryAddExpr(BLangExpression lExpr, BLangExpression rExpr, BSymbol opSymbol) {
    BLangBinaryExpr binaryExpressionNode = (BLangBinaryExpr) TreeBuilder.createBinaryExpressionNode();
    binaryExpressionNode.lhsExpr = lExpr;
    binaryExpressionNode.rhsExpr = rExpr;
    binaryExpressionNode.pos = rExpr.pos;
    binaryExpressionNode.opKind = OperatorKind.ADD;
    if (opSymbol != symTable.notFoundSymbol) {
        binaryExpressionNode.type = opSymbol.type.getReturnTypes().get(0);
        binaryExpressionNode.opSymbol = (BOperatorSymbol) opSymbol;
    } else {
        binaryExpressionNode.type = symTable.errType;
    }
    types.checkType(binaryExpressionNode, binaryExpressionNode.type, symTable.stringType);
    return binaryExpressionNode;
}
Also used : BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)

Example 12 with BOperatorSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol in project ballerina by ballerina-lang.

the class SymbolTable method defineOperator.

private void defineOperator(Name name, List<BType> paramTypes, List<BType> retTypes, int opcode) {
    BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
    BOperatorSymbol symbol = new BOperatorSymbol(name, rootPkgSymbol.pkgID, opType, rootPkgSymbol, opcode);
    rootScope.define(name, symbol);
}
Also used : BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol)

Example 13 with BOperatorSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol in project ballerina by ballerina-lang.

the class Symbols method createTypeofOperatorSymbol.

public static BOperatorSymbol createTypeofOperatorSymbol(BType exprType, Types types, SymbolTable symTable, Names names) {
    List<BType> paramTypes = Lists.of(exprType);
    List<BType> retTypes = Lists.of(symTable.typeDesc);
    BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
    if (types.isValueType(exprType)) {
        return new BOperatorSymbol(names.fromString(OperatorKind.TYPEOF.value()), symTable.rootPkgSymbol.pkgID, opType, symTable.rootPkgSymbol, InstructionCodes.TYPELOAD);
    } else {
        return new BOperatorSymbol(names.fromString(OperatorKind.TYPEOF.value()), symTable.rootPkgSymbol.pkgID, opType, symTable.rootPkgSymbol, InstructionCodes.TYPEOF);
    }
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)

Example 14 with BOperatorSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol in project ballerina by ballerina-lang.

the class ASTBuilderUtil method createIsAssignableExpr.

static BLangIsAssignableExpr createIsAssignableExpr(DiagnosticPos pos, BLangExpression lhsExpr, BType targetType, BType type, Names names) {
    final BLangIsAssignableExpr assignableExpr = new BLangIsAssignableExpr();
    assignableExpr.pos = pos;
    assignableExpr.lhsExpr = lhsExpr;
    assignableExpr.targetType = targetType;
    assignableExpr.type = type;
    assignableExpr.opSymbol = new BOperatorSymbol(names.fromString(assignableExpr.opKind.value()), null, targetType, null, InstructionCodes.IS_ASSIGNABLE);
    return assignableExpr;
}
Also used : BLangIsAssignableExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIsAssignableExpr) BOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol)

Example 15 with BOperatorSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol in project ballerina by ballerina-lang.

the class ASTBuilderUtil method createBinaryExpr.

static BLangBinaryExpr createBinaryExpr(DiagnosticPos pos, BLangExpression lhsExpr, BLangExpression rhsExpr, BType type, OperatorKind opKind, BOperatorSymbol symbol) {
    final BLangBinaryExpr binaryExpr = (BLangBinaryExpr) TreeBuilder.createBinaryExpressionNode();
    binaryExpr.pos = pos;
    binaryExpr.lhsExpr = lhsExpr;
    binaryExpr.rhsExpr = rhsExpr;
    binaryExpr.type = type;
    binaryExpr.opKind = opKind;
    binaryExpr.opSymbol = symbol;
    return binaryExpr;
}
Also used : BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)

Aggregations

BLangBinaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)8 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)6 BOperatorSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol)5 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)5 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)5 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)3 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)3 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)2 BLangUnaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangUnaryExpr)2 BLangIf (org.wso2.ballerinalang.compiler.tree.statements.BLangIf)2 ArrayList (java.util.ArrayList)1 SymbolInfo (org.ballerinalang.langserver.completions.SymbolInfo)1 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)1 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)1 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)1 BUnionType (org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangIsAssignableExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangIsAssignableExpr)1 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)1