use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class TypeChecker method checkInvocationArgs.
private List<BType> checkInvocationArgs(BLangInvocation iExpr, List<BType> paramTypes, int requiredParamsCount, BLangExpression vararg) {
List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
BInvokableSymbol invocableSymbol = (BInvokableSymbol) iExpr.symbol;
// Check whether the expected param count and the actual args counts are matching.
if (requiredParamsCount > iExpr.requiredArgs.size()) {
dlog.error(iExpr.pos, DiagnosticCode.NOT_ENOUGH_ARGS_FUNC_CALL, iExpr.name.value);
return actualTypes;
} else if (invocableSymbol.restParam == null && (vararg != null || !iExpr.restArgs.isEmpty())) {
dlog.error(iExpr.pos, DiagnosticCode.TOO_MANY_ARGS_FUNC_CALL, iExpr.name.value);
return actualTypes;
}
// formal parameters of the outer function.
if (iExpr.argExprs.size() == 1 && iExpr.argExprs.get(0).getKind() == NodeKind.INVOCATION) {
checkExpr(iExpr.requiredArgs.get(0), this.env, ((BInvokableType) invocableSymbol.type).paramTypes);
} else {
checkRequiredArgs(iExpr.requiredArgs, paramTypes);
}
checkNamedArgs(iExpr.namedArgs, invocableSymbol.defaultableParams);
checkRestArgs(iExpr.restArgs, vararg, invocableSymbol.restParam);
if (iExpr.async) {
return Arrays.asList(this.generateFutureType(invocableSymbol));
} else {
return invocableSymbol.type.getReturnTypes();
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class Symbols method createConversionOperatorSymbol.
public static BConversionOperatorSymbol createConversionOperatorSymbol(final BType sourceType, final BType targetType, final BType errorType, boolean implicit, boolean safe, int opcode, PackageID pkgID, BSymbol owner) {
List<BType> paramTypes = Lists.of(sourceType, targetType);
List<BType> retTypes = new ArrayList<>(1);
if (safe) {
retTypes.add(targetType);
} else if (targetType.tag == TypeTags.UNION && targetType instanceof BUnionType) {
BUnionType unionType = (BUnionType) targetType;
unionType.memberTypes.add(errorType);
retTypes.add(unionType);
} else {
Set<BType> memberTypes = new HashSet<>(2);
memberTypes.add(targetType);
memberTypes.add(errorType);
BUnionType unionType = new BUnionType(null, memberTypes, false);
retTypes.add(unionType);
}
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
BConversionOperatorSymbol symbol = new BConversionOperatorSymbol(pkgID, opType, owner, implicit, safe, opcode);
symbol.kind = SymbolKind.CONVERSION_OPERATOR;
return symbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class CodeGenerator method createActionInfoEntry.
private void createActionInfoEntry(BLangAction actionNode, ConnectorInfo connectorInfo) {
BInvokableSymbol actionSymbol = actionNode.symbol;
BInvokableType actionType = (BInvokableType) actionSymbol.type;
// Add action name as an UTFCPEntry to the constant pool
int actionNameCPIndex = addUTF8CPEntry(currentPkgInfo, actionNode.name.value);
ActionInfo actionInfo = new ActionInfo(currentPackageRefCPIndex, actionNameCPIndex);
actionInfo.paramTypes = actionType.paramTypes.toArray(new BType[0]);
actionInfo.retParamTypes = actionType.retTypes.toArray(new BType[0]);
actionInfo.flags = actionSymbol.flags;
// setParameterNames(actionNode, actionInfo);
actionInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(actionInfo.paramTypes, actionInfo.retParamTypes));
// Add worker info
this.addWorkerInfoEntries(actionInfo, actionNode.getWorkers());
// Add parameter default value info
addParameterDefaultValues(actionNode, actionInfo);
// Add action info to the connector info
connectorInfo.actionInfoMap.put(actionNode.name.getValue(), actionInfo);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class CodeGenerator method createFunctionInfoEntry.
/**
* Creates a {@code FunctionInfo} from the given function node in AST.
*
* @param funcNode function node in AST
*/
private void createFunctionInfoEntry(BLangFunction funcNode) {
BInvokableSymbol funcSymbol = funcNode.symbol;
BInvokableType funcType = (BInvokableType) funcSymbol.type;
// Add function name as an UTFCPEntry to the constant pool
int funcNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, funcNode.name.value);
FunctionInfo funcInfo = new FunctionInfo(currentPackageRefCPIndex, funcNameCPIndex);
funcInfo.paramTypes = funcType.paramTypes.toArray(new BType[0]);
funcInfo.retParamTypes = funcType.retTypes.toArray(new BType[0]);
funcInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(funcInfo.paramTypes, funcInfo.retParamTypes));
funcInfo.flags = funcSymbol.flags;
if (funcNode.receiver != null) {
funcInfo.attachedToTypeCPIndex = getTypeCPIndex(funcNode.receiver.type).value;
}
this.addWorkerInfoEntries(funcInfo, funcNode.getWorkers());
// Add parameter default value info
addParameterDefaultValues(funcNode, funcInfo);
this.currentPkgInfo.functionInfoMap.put(funcSymbol.name.value, funcInfo);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangFunction funcNode) {
SymbolEnv fucEnv = SymbolEnv.createFunctionEnv(funcNode, funcNode.symbol.scope, env);
if (!funcNode.interfaceFunction) {
addReturnIfNotPresent(funcNode);
}
// To preserve endpoint code gen order.
Collections.reverse(funcNode.endpoints);
funcNode.endpoints = rewrite(funcNode.endpoints, fucEnv);
funcNode.body = rewrite(funcNode.body, fucEnv);
funcNode.workers = rewrite(funcNode.workers, fucEnv);
// the struct variable as the first parameter
if (funcNode.receiver != null) {
BInvokableSymbol funcSymbol = funcNode.symbol;
List<BVarSymbol> params = funcSymbol.params;
params.add(0, funcNode.receiver.symbol);
BInvokableType funcType = (BInvokableType) funcSymbol.type;
funcType.paramTypes.add(0, funcNode.receiver.type);
}
result = funcNode;
}
Aggregations