Search in sources :

Example 1 with SymbolResolver

use of org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver in project ballerina by ballerina-lang.

the class ASTBuilderUtil method generateConversionExpr.

static BLangExpression generateConversionExpr(BLangExpression varRef, BType target, SymbolResolver symResolver) {
    if (varRef.type.tag == target.tag || varRef.type.tag > TypeTags.TYPEDESC) {
        return varRef;
    }
    // Box value using cast expression.
    final BLangTypeConversionExpr conversion = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
    conversion.pos = varRef.pos;
    conversion.expr = varRef;
    conversion.type = target;
    conversion.targetType = target;
    conversion.conversionSymbol = (BConversionOperatorSymbol) symResolver.resolveConversionOperator(varRef.type, target);
    return conversion;
}
Also used : BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr)

Example 2 with SymbolResolver

use of org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver in project ballerina by ballerina-lang.

the class ASTBuilderUtil method generateArgExprs.

static List<BLangExpression> generateArgExprs(DiagnosticPos pos, List<BLangVariable> args, List<BVarSymbol> formalParams, SymbolResolver symResolver) {
    List<BLangExpression> argsExpr = new ArrayList<>();
    final List<BLangSimpleVarRef> variableRefList = createVariableRefList(pos, args);
    for (int i = 0; i < variableRefList.size(); i++) {
        BLangSimpleVarRef varRef = variableRefList.get(i);
        BType target = formalParams.get(i).type;
        BType source = varRef.symbol.type;
        if (source != target) {
            argsExpr.add(generateConversionExpr(varRef, target, symResolver));
            continue;
        }
        argsExpr.add(varRef);
    }
    return argsExpr;
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 3 with SymbolResolver

use of org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver in project ballerina by ballerina-lang.

the class ASTBuilderUtil method createInvocationExpr.

static BLangInvocation createInvocationExpr(DiagnosticPos pos, BInvokableSymbol invokableSymbol, List<BLangVariable> requiredArgs, List<BLangVariable> namedArgs, List<BLangVariable> restArgs, SymbolResolver symResolver) {
    final BLangInvocation invokeLambda = (BLangInvocation) TreeBuilder.createInvocationNode();
    invokeLambda.pos = pos;
    invokeLambda.requiredArgs.addAll(generateArgExprs(pos, requiredArgs, invokableSymbol.params, symResolver));
    invokeLambda.namedArgs.addAll(generateArgExprs(pos, namedArgs, invokableSymbol.defaultableParams, symResolver));
    invokeLambda.restArgs.addAll(generateArgExprs(pos, restArgs, Lists.of(invokableSymbol.restParam), symResolver));
    invokeLambda.symbol = invokableSymbol;
    invokeLambda.types.addAll(((BInvokableType) invokableSymbol.type).retTypes);
    if (!invokeLambda.types.isEmpty()) {
        invokeLambda.type = invokeLambda.types.get(0);
    }
    return invokeLambda;
}
Also used : BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)

Aggregations

ArrayList (java.util.ArrayList)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)1 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)1 BLangTypeConversionExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr)1