Search in sources :

Example 21 with BLangInvocation

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;
}
Also used : BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BNullType(org.wso2.ballerinalang.compiler.semantics.model.types.BNullType)

Example 22 with BLangInvocation

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);
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 23 with BLangInvocation

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;
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)

Example 24 with BLangInvocation

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;
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 25 with BLangInvocation

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;
}
Also used : DefaultValue(org.wso2.ballerinalang.programfile.DefaultValue) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) ConnectorInfo(org.wso2.ballerinalang.programfile.ConnectorInfo) ImportPackageInfo(org.wso2.ballerinalang.programfile.ImportPackageInfo) PackageInfo(org.wso2.ballerinalang.programfile.PackageInfo) CallableUnitInfo(org.wso2.ballerinalang.programfile.CallableUnitInfo) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)22 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)12 ArrayList (java.util.ArrayList)11 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)9 Name (org.wso2.ballerinalang.compiler.util.Name)8 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)6 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)5 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 List (java.util.List)4 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)4 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)4 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)4 Paths (java.nio.file.Paths)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)3 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)3