Search in sources :

Example 6 with CallableUnitInfo

use of org.wso2.ballerinalang.programfile.CallableUnitInfo 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

BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)6 BLangWorker (org.wso2.ballerinalang.compiler.tree.BLangWorker)2 DefaultValue (org.wso2.ballerinalang.programfile.DefaultValue)2 WorkerInfo (org.wso2.ballerinalang.programfile.WorkerInfo)2 ParamDefaultValueAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo)2 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)2 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)1 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)1 CallableUnitInfo (org.wso2.ballerinalang.programfile.CallableUnitInfo)1 ConnectorInfo (org.wso2.ballerinalang.programfile.ConnectorInfo)1 ImportPackageInfo (org.wso2.ballerinalang.programfile.ImportPackageInfo)1 PackageInfo (org.wso2.ballerinalang.programfile.PackageInfo)1 WorkerDataChannelInfo (org.wso2.ballerinalang.programfile.WorkerDataChannelInfo)1 LocalVariableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo)1