Search in sources :

Example 1 with ParamDefaultValueAttributeInfo

use of org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo in project ballerina by ballerina-lang.

the class PackageInfoWriter method writeAttributeInfo.

private static void writeAttributeInfo(DataOutputStream dataOutStream, AttributeInfo attributeInfo) throws IOException {
    AttributeInfo.Kind attributeKind = attributeInfo.getKind();
    dataOutStream.writeInt(attributeInfo.getAttributeNameIndex());
    switch(attributeKind) {
        case CODE_ATTRIBUTE:
            CodeAttributeInfo codeAttributeInfo = (CodeAttributeInfo) attributeInfo;
            dataOutStream.writeInt(codeAttributeInfo.codeAddrs);
            dataOutStream.writeShort(codeAttributeInfo.maxLongLocalVars);
            dataOutStream.writeShort(codeAttributeInfo.maxDoubleLocalVars);
            dataOutStream.writeShort(codeAttributeInfo.maxStringLocalVars);
            dataOutStream.writeShort(codeAttributeInfo.maxIntLocalVars);
            dataOutStream.writeShort(codeAttributeInfo.maxByteLocalVars);
            dataOutStream.writeShort(codeAttributeInfo.maxRefLocalVars);
            dataOutStream.writeShort(codeAttributeInfo.maxLongRegs);
            dataOutStream.writeShort(codeAttributeInfo.maxDoubleRegs);
            dataOutStream.writeShort(codeAttributeInfo.maxStringRegs);
            dataOutStream.writeShort(codeAttributeInfo.maxIntRegs);
            dataOutStream.writeShort(codeAttributeInfo.maxByteRegs);
            dataOutStream.writeShort(codeAttributeInfo.maxRefRegs);
            break;
        case VARIABLE_TYPE_COUNT_ATTRIBUTE:
            VarTypeCountAttributeInfo varCountAttributeInfo = (VarTypeCountAttributeInfo) attributeInfo;
            dataOutStream.writeShort(varCountAttributeInfo.getMaxLongVars());
            dataOutStream.writeShort(varCountAttributeInfo.getMaxDoubleVars());
            dataOutStream.writeShort(varCountAttributeInfo.getMaxStringVars());
            dataOutStream.writeShort(varCountAttributeInfo.getMaxIntVars());
            dataOutStream.writeShort(varCountAttributeInfo.getMaxByteVars());
            dataOutStream.writeShort(varCountAttributeInfo.getMaxRefVars());
            break;
        case ERROR_TABLE:
            ErrorTableAttributeInfo errTable = (ErrorTableAttributeInfo) attributeInfo;
            ErrorTableEntry[] errorTableEntries = errTable.getErrorTableEntriesList().toArray(new ErrorTableEntry[0]);
            dataOutStream.writeShort(errorTableEntries.length);
            for (ErrorTableEntry errorTableEntry : errorTableEntries) {
                dataOutStream.writeInt(errorTableEntry.ipFrom);
                dataOutStream.writeInt(errorTableEntry.ipTo);
                dataOutStream.writeInt(errorTableEntry.ipTarget);
                dataOutStream.writeInt(errorTableEntry.priority);
                dataOutStream.writeInt(errorTableEntry.errorStructCPIndex);
            }
            break;
        case LOCAL_VARIABLES_ATTRIBUTE:
            LocalVariableAttributeInfo localVarAttrInfo = (LocalVariableAttributeInfo) attributeInfo;
            LocalVariableInfo[] localVarInfoArray = localVarAttrInfo.localVars.toArray(new LocalVariableInfo[0]);
            dataOutStream.writeShort(localVarInfoArray.length);
            for (LocalVariableInfo localVariableInfo : localVarInfoArray) {
                writeLocalVariableInfo(dataOutStream, localVariableInfo);
            }
            break;
        case LINE_NUMBER_TABLE_ATTRIBUTE:
            LineNumberTableAttributeInfo lnNoTblAttrInfo = (LineNumberTableAttributeInfo) attributeInfo;
            LineNumberInfo[] lineNumberInfoEntries = lnNoTblAttrInfo.getLineNumberInfoEntries();
            dataOutStream.writeShort(lineNumberInfoEntries.length);
            for (LineNumberInfo lineNumberInfo : lineNumberInfoEntries) {
                writeLineNumberInfo(dataOutStream, lineNumberInfo);
            }
            break;
        case DEFAULT_VALUE_ATTRIBUTE:
            DefaultValueAttributeInfo defaultValAttrInfo = (DefaultValueAttributeInfo) attributeInfo;
            writeDefaultValue(dataOutStream, defaultValAttrInfo.getDefaultValue());
            break;
        case PARAMETER_DEFAULTS_ATTRIBUTE:
            ParamDefaultValueAttributeInfo paramDefaultValAttrInfo = (ParamDefaultValueAttributeInfo) attributeInfo;
            DefaultValue[] defaultValues = paramDefaultValAttrInfo.getDefaultValueInfo();
            dataOutStream.writeShort(defaultValues.length);
            for (DefaultValue defaultValue : defaultValues) {
                writeDefaultValue(dataOutStream, defaultValue);
            }
            break;
    }
// TODO Support other types of attributes
}
Also used : VarTypeCountAttributeInfo(org.wso2.ballerinalang.programfile.attributes.VarTypeCountAttributeInfo) LineNumberTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LineNumberTableAttributeInfo) CodeAttributeInfo(org.wso2.ballerinalang.programfile.attributes.CodeAttributeInfo) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) LineNumberTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LineNumberTableAttributeInfo) ErrorTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo) AttributeInfo(org.wso2.ballerinalang.programfile.attributes.AttributeInfo) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) DefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo) VarTypeCountAttributeInfo(org.wso2.ballerinalang.programfile.attributes.VarTypeCountAttributeInfo) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) DefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo) ErrorTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo) CodeAttributeInfo(org.wso2.ballerinalang.programfile.attributes.CodeAttributeInfo)

Example 2 with ParamDefaultValueAttributeInfo

use of org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo in project ballerina by ballerina-lang.

the class CodeGenerator method addParameterDefaultValues.

private void addParameterDefaultValues(BLangInvokableNode invokableNode, CallableUnitInfo callableUnitInfo) {
    int paramDefaultsAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE.value());
    ParamDefaultValueAttributeInfo paramDefaulValAttrInfo = new ParamDefaultValueAttributeInfo(paramDefaultsAttrNameIndex);
    // Only named parameters can have default values.
    for (BLangVariableDef param : invokableNode.defaultableParams) {
        DefaultValue defaultVal = getDefaultValue((BLangLiteral) param.var.expr);
        paramDefaulValAttrInfo.addParamDefaultValueInfo(defaultVal);
    }
    callableUnitInfo.addAttributeInfo(AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE, paramDefaulValAttrInfo);
}
Also used : DefaultValue(org.wso2.ballerinalang.programfile.DefaultValue) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 3 with ParamDefaultValueAttributeInfo

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

ParamDefaultValueAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo)3 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 DefaultValue (org.wso2.ballerinalang.programfile.DefaultValue)2 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)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 AttributeInfo (org.wso2.ballerinalang.programfile.attributes.AttributeInfo)1 CodeAttributeInfo (org.wso2.ballerinalang.programfile.attributes.CodeAttributeInfo)1 DefaultValueAttributeInfo (org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo)1 ErrorTableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo)1 LineNumberTableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.LineNumberTableAttributeInfo)1 LocalVariableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo)1 VarTypeCountAttributeInfo (org.wso2.ballerinalang.programfile.attributes.VarTypeCountAttributeInfo)1