use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.
the class ServiceProtoUtils method getResponseMessage.
private static Message getResponseMessage(ResourceNode resourceNode) throws GrpcServerException {
org.wso2.ballerinalang.compiler.semantics.model.types.BType responseType;
BLangInvocation sendExpression = getInvocationExpression(resourceNode.getBody());
if (sendExpression != null) {
responseType = getReturnType(sendExpression);
} else {
// if compiler plugin could not find
responseType = new BNullType();
}
return responseType != null ? generateMessageDefinition(responseType) : null;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.
the class TypeChecker method checkFunctionInvocationExpr.
private void checkFunctionInvocationExpr(BLangInvocation iExpr) {
Name funcName = names.fromIdNode(iExpr.name);
Name pkgAlias = names.fromIdNode(iExpr.pkgAlias);
BSymbol funcSymbol = symResolver.lookupSymbolInPackage(iExpr.pos, env, pkgAlias, funcName, SymTag.VARIABLE);
if (funcSymbol == symTable.notFoundSymbol || funcSymbol.type.tag != TypeTags.INVOKABLE) {
dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_FUNCTION, funcName);
resultTypes = getListWithErrorTypes(expTypes.size());
return;
}
if (funcSymbol.tag == SymTag.VARIABLE) {
// Check for function pointer.
iExpr.functionPointerInvocation = true;
}
// Set the resolved function symbol in the invocation expression.
// This is used in the code generation phase.
iExpr.symbol = funcSymbol;
checkInvocationParamAndReturnType(iExpr);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.
the class TypeChecker method checkNamedTransformerInvocation.
private List<BType> checkNamedTransformerInvocation(BLangTypeConversionExpr conversionExpr, BType sourceType, BType targetType) {
List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
BLangInvocation transformerInvocation = conversionExpr.transformerInvocation;
BSymbol transformerSymbol = symResolver.lookupSymbolInPackage(transformerInvocation.pos, env, names.fromIdNode(transformerInvocation.pkgAlias), names.fromIdNode(transformerInvocation.name), SymTag.TRANSFORMER);
if (transformerSymbol == symTable.notFoundSymbol) {
dlog.error(conversionExpr.pos, DiagnosticCode.UNDEFINED_TRANSFORMER, transformerInvocation.name);
} else {
conversionExpr.conversionSymbol = (BConversionOperatorSymbol) (transformerInvocation.symbol = transformerSymbol);
// Check the transformer invocation. Expected type for the transformer is the target type
// of the cast conversion operator, but not the lhs type.
List<BType> prevExpType = expTypes;
expTypes = Lists.of(targetType);
checkInvocationParamAndReturnType(transformerInvocation);
expTypes = prevExpType;
if (transformerInvocation.type != symTable.errType) {
BInvokableType transformerSymType = (BInvokableType) transformerSymbol.type;
transformerInvocation.types = transformerSymType.retTypes;
actualTypes = getActualTypesOfConversionExpr(conversionExpr, targetType, sourceType, conversionExpr.conversionSymbol);
}
}
return actualTypes;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.
the class CodeGenerator method getFuncOperands.
private Operand[] getFuncOperands(BLangInvocation iExpr, int funcRefCPIndex) {
// call funcRefCPIndex, nArgRegs, argRegs[nArgRegs], nRetRegs, retRegs[nRetRegs]
int i = 0;
int nArgRegs = iExpr.requiredArgs.size() + iExpr.namedArgs.size() + iExpr.restArgs.size();
int nRetRegs = iExpr.types.size();
int flags = FunctionFlags.NOTHING;
Operand[] operands = new Operand[nArgRegs + nRetRegs + 4];
operands[i++] = getOperand(funcRefCPIndex);
if (iExpr.async) {
flags = FunctionFlags.markAsync(flags);
}
if (iExpr.actionInvocation) {
flags = FunctionFlags.markObserved(flags);
}
operands[i++] = getOperand(flags);
operands[i++] = getOperand(nArgRegs);
// Write required arguments
for (BLangExpression argExpr : iExpr.requiredArgs) {
operands[i++] = genNode(argExpr, this.env).regIndex;
}
// Write named arguments
i = generateNamedArgs(iExpr, operands, i);
// Write rest arguments
for (BLangExpression argExpr : iExpr.restArgs) {
operands[i++] = genNode(argExpr, this.env).regIndex;
}
// Calculate registers to store return values
operands[i++] = getOperand(nRetRegs);
RegIndex[] iExprRegIndexes;
if (iExpr.regIndex != null) {
iExprRegIndexes = new RegIndex[nRetRegs];
iExprRegIndexes[0] = iExpr.regIndex;
} else {
iExprRegIndexes = new RegIndex[nRetRegs];
}
for (int j = 0; j < nRetRegs; j++) {
RegIndex regIndex = calcAndGetExprRegIndex(iExprRegIndexes[j], iExpr.getTypes().get(j).tag);
iExprRegIndexes[j] = regIndex;
operands[i++] = regIndex;
}
iExpr.setRegIndexes(iExprRegIndexes);
return operands;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.
the class CodeGenerator method generateNamedArgs.
private int generateNamedArgs(BLangInvocation iExpr, Operand[] operands, int currentIndex) {
if (iExpr.namedArgs.isEmpty()) {
return currentIndex;
}
PackageInfo pkgInfo = programFile.packageInfoMap.get(iExpr.symbol.pkgID.bvmAlias());
CallableUnitInfo callableUnitInfo;
if (iExpr.symbol.kind == SymbolKind.FUNCTION) {
callableUnitInfo = pkgInfo.functionInfoMap.get(iExpr.symbol.name.value);
} else if (iExpr.symbol.kind == SymbolKind.ACTION) {
ConnectorInfo connectorInfo = pkgInfo.connectorInfoMap.get(iExpr.symbol.owner.name.value);
callableUnitInfo = connectorInfo.actionInfoMap.get(iExpr.symbol.name.value);
} else {
throw new IllegalStateException("Unsupported callable unit");
}
ParamDefaultValueAttributeInfo defaultValAttrInfo = (ParamDefaultValueAttributeInfo) callableUnitInfo.getAttributeInfo(AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE);
for (int i = 0; i < iExpr.namedArgs.size(); i++) {
BLangExpression argExpr = iExpr.namedArgs.get(i);
// at this point. If so, get the default value for that parameter from the function info.
if (argExpr == null) {
DefaultValue defaultVal = defaultValAttrInfo.getDefaultValueInfo()[i];
argExpr = getDefaultValExpr(defaultVal);
}
operands[currentIndex++] = genNode(argExpr, this.env).regIndex;
}
return currentIndex;
}
Aggregations