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