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