use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class SymbolResolver method visit.
@Override
public void visit(BLangFunctionTypeNode functionTypeNode) {
List<BType> paramTypes = new ArrayList<>();
List<BType> retParamTypes = new ArrayList<>();
functionTypeNode.getParamTypeNode().forEach(t -> paramTypes.add(resolveTypeNode((BLangType) t, env)));
functionTypeNode.getReturnParamTypeNode().forEach(t -> retParamTypes.add(resolveTypeNode((BLangType) t, env)));
resultType = new BInvokableType(paramTypes, retParamTypes, null);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class SymbolResolver method getBinaryOpForNullChecks.
private BSymbol getBinaryOpForNullChecks(OperatorKind opKind, BType lhsType, BType rhsType) {
if (opKind != OperatorKind.EQUAL && opKind != OperatorKind.NOT_EQUAL) {
return symTable.notFoundSymbol;
}
int opcode = (opKind == OperatorKind.EQUAL) ? InstructionCodes.REQ_NULL : InstructionCodes.RNE_NULL;
if (lhsType.tag == TypeTags.NULL && (rhsType.tag == TypeTags.STRUCT || rhsType.tag == TypeTags.CONNECTOR || rhsType.tag == TypeTags.ENUM || rhsType.tag == TypeTags.INVOKABLE)) {
List<BType> paramTypes = Lists.of(lhsType, rhsType);
List<BType> retTypes = Lists.of(symTable.booleanType);
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
}
if ((lhsType.tag == TypeTags.STRUCT || lhsType.tag == TypeTags.CONNECTOR || lhsType.tag == TypeTags.ENUM || lhsType.tag == TypeTags.INVOKABLE) && rhsType.tag == TypeTags.NULL) {
List<BType> paramTypes = Lists.of(lhsType, rhsType);
List<BType> retTypes = Lists.of(symTable.booleanType);
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
}
if (lhsType.tag == TypeTags.ENUM && rhsType.tag == TypeTags.ENUM && lhsType == rhsType) {
opcode = (opKind == OperatorKind.EQUAL) ? InstructionCodes.REQ : InstructionCodes.RNE;
List<BType> paramTypes = Lists.of(lhsType, rhsType);
List<BType> retTypes = Lists.of(symTable.booleanType);
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
}
return symTable.notFoundSymbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class SymbolResolver method resolveOperator.
private BSymbol resolveOperator(ScopeEntry entry, List<BType> types) {
BSymbol foundSymbol = symTable.notFoundSymbol;
while (entry != NOT_FOUND_ENTRY) {
BInvokableType opType = (BInvokableType) entry.symbol.type;
if (types.size() == opType.paramTypes.size()) {
boolean match = true;
for (int i = 0; i < types.size(); i++) {
if (types.get(i).tag != opType.paramTypes.get(i).tag) {
match = false;
}
}
if (match) {
foundSymbol = entry.symbol;
break;
}
}
entry = entry.next;
}
return foundSymbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class SemanticAnalyzer method defineResourceEndpoint.
private void defineResourceEndpoint(BLangResource resourceNode, SymbolEnv resourceEnv) {
if (!resourceNode.getParameters().isEmpty()) {
final BLangVariable variable = resourceNode.getParameters().get(0);
if (variable.type == symTable.endpointType) {
String actualVarName = variable.name.value.substring(1);
variable.name = new BLangIdentifier();
variable.name.value = actualVarName;
if (resourceEnv.enclService.endpointType != null) {
variable.type = resourceEnv.enclService.endpointType;
final BEndpointVarSymbol bEndpointVarSymbol = symbolEnter.defineEndpointVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
variable.symbol = bEndpointVarSymbol;
endpointSPIAnalyzer.populateEndpointSymbol((BStructSymbol) variable.type.tsymbol, bEndpointVarSymbol);
} else {
variable.type = symTable.errType;
variable.symbol = symbolEnter.defineVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
}
// Replace old symbol with new one.
resourceNode.symbol.params.remove(0);
resourceNode.symbol.params.add(0, variable.symbol);
((BInvokableType) resourceNode.symbol.type).paramTypes.remove(0);
((BInvokableType) resourceNode.symbol.type).paramTypes.add(0, variable.type);
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType 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);
}
Aggregations