Search in sources :

Example 1 with BLangNamedArgsExpression

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangNamedArgsExpression in project ballerina by ballerina-lang.

the class TypeChecker method checkInvocationParam.

private List<BType> checkInvocationParam(BLangInvocation iExpr) {
    List<BType> paramTypes = ((BInvokableType) iExpr.symbol.type).getParameterTypes();
    int requiredParamsCount;
    if (iExpr.symbol.tag == SymTag.VARIABLE) {
        // Here we assume function pointers can have only required params.
        // And assume that named params and rest params are not supported.
        requiredParamsCount = paramTypes.size();
    } else {
        requiredParamsCount = ((BInvokableSymbol) iExpr.symbol).params.size();
    }
    // Split the different argument types: required args, named args and rest args
    int i = 0;
    BLangExpression vararg = null;
    for (BLangExpression expr : iExpr.argExprs) {
        switch(expr.getKind()) {
            case NAMED_ARGS_EXPR:
                iExpr.namedArgs.add((BLangNamedArgsExpression) expr);
                break;
            case REST_ARGS_EXPR:
                vararg = expr;
                break;
            default:
                if (i < requiredParamsCount) {
                    iExpr.requiredArgs.add(expr);
                } else {
                    iExpr.restArgs.add(expr);
                }
                i++;
                break;
        }
    }
    return checkInvocationArgs(iExpr, paramTypes, requiredParamsCount, vararg);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 2 with BLangNamedArgsExpression

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangNamedArgsExpression in project ballerina by ballerina-lang.

the class CodeAnalyzer method checkDuplicateNamedArgs.

private void checkDuplicateNamedArgs(List<BLangExpression> args) {
    List<BLangIdentifier> existingArgs = new ArrayList<>();
    args.forEach(arg -> {
        BLangNamedArgsExpression namedArg = (BLangNamedArgsExpression) arg;
        if (existingArgs.contains(namedArg.name)) {
            dlog.error(namedArg.pos, DiagnosticCode.DUPLICATE_NAMED_ARGS, namedArg.name);
        }
        existingArgs.add(namedArg.name);
    });
}
Also used : ArrayList(java.util.ArrayList) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangNamedArgsExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangNamedArgsExpression)

Example 3 with BLangNamedArgsExpression

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangNamedArgsExpression in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addNamedArgument.

public void addNamedArgument(DiagnosticPos pos, Set<Whitespace> ws, String name) {
    BLangNamedArgsExpression namedArg = (BLangNamedArgsExpression) TreeBuilder.createNamedArgNode();
    namedArg.pos = pos;
    namedArg.addWS(ws);
    namedArg.name = (BLangIdentifier) this.createIdentifier(name);
    namedArg.expr = (BLangExpression) this.exprNodeStack.pop();
    addExpressionNode(namedArg);
}
Also used : BLangNamedArgsExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangNamedArgsExpression)

Aggregations

BLangNamedArgsExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangNamedArgsExpression)2 ArrayList (java.util.ArrayList)1 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)1 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1