Search in sources :

Example 6 with UTF8CPEntry

use of org.ballerinalang.util.codegen.cpentries.UTF8CPEntry in project ballerina by ballerina-lang.

the class ProgramFileReader method readConnectorInfoEntries.

private void readConnectorInfoEntries(DataInputStream dataInStream, PackageInfo packageInfo) throws IOException {
    int connectorCount = dataInStream.readShort();
    for (int i = 0; i < connectorCount; i++) {
        // Read connector name cp index
        int connectorNameCPIndex = dataInStream.readInt();
        UTF8CPEntry connectorNameUTF8Entry = (UTF8CPEntry) packageInfo.getCPEntry(connectorNameCPIndex);
        int flags = dataInStream.readInt();
        // Create connector info
        String connectorName = connectorNameUTF8Entry.getValue();
        ConnectorInfo connectorInfo = new ConnectorInfo(packageInfo.getPkgNameCPIndex(), packageInfo.getPkgPath(), connectorNameCPIndex, connectorName, flags);
        packageInfo.addConnectorInfo(connectorName, connectorInfo);
        // Set connector type
        BConnectorType bConnectorType = new BConnectorType(connectorName, packageInfo.getPkgPath());
        connectorInfo.setType(bConnectorType);
    }
}
Also used : UTF8CPEntry(org.ballerinalang.util.codegen.cpentries.UTF8CPEntry) BConnectorType(org.ballerinalang.model.types.BConnectorType)

Example 7 with UTF8CPEntry

use of org.ballerinalang.util.codegen.cpentries.UTF8CPEntry in project ballerina by ballerina-lang.

the class ProgramFileReader method readServiceInfoEntries.

private void readServiceInfoEntries(DataInputStream dataInStream, PackageInfo packageInfo) throws IOException {
    int serviceCount = dataInStream.readShort();
    for (int i = 0; i < serviceCount; i++) {
        // Read connector name cp index
        int serviceNameCPIndex = dataInStream.readInt();
        UTF8CPEntry serviceNameUTF8Entry = (UTF8CPEntry) packageInfo.getCPEntry(serviceNameCPIndex);
        int flags = dataInStream.readInt();
        // Read connector signature cp index;
        int endpointNameCPIndex = dataInStream.readInt();
        UTF8CPEntry endpointNameUTF8Entry = (UTF8CPEntry) packageInfo.getCPEntry(endpointNameCPIndex);
        ServiceInfo serviceInfo = new ServiceInfo(packageInfo.getPkgNameCPIndex(), packageInfo.getPkgPath(), serviceNameCPIndex, serviceNameUTF8Entry.getValue(), flags, endpointNameCPIndex, endpointNameUTF8Entry.getValue());
        serviceInfo.setPackageInfo(packageInfo);
        packageInfo.addServiceInfo(serviceInfo.getName(), serviceInfo);
        serviceInfo.setType(new BServiceType(serviceInfo.getName(), packageInfo.getPkgPath()));
    }
}
Also used : UTF8CPEntry(org.ballerinalang.util.codegen.cpentries.UTF8CPEntry) BServiceType(org.ballerinalang.model.types.BServiceType)

Example 8 with UTF8CPEntry

use of org.ballerinalang.util.codegen.cpentries.UTF8CPEntry in project ballerina by ballerina-lang.

the class ProgramFileReader method getDefaultValue.

private DefaultValue getDefaultValue(DataInputStream dataInStream, ConstantPool constantPool) throws IOException {
    DefaultValue defaultValue;
    int typeDescCPIndex = dataInStream.readInt();
    UTF8CPEntry typeDescCPEntry = (UTF8CPEntry) constantPool.getCPEntry(typeDescCPIndex);
    String typeDesc = typeDescCPEntry.getValue();
    int valueCPIndex;
    switch(typeDesc) {
        case TypeSignature.SIG_BOOLEAN:
            boolean boolValue = dataInStream.readBoolean();
            defaultValue = new DefaultValue(typeDescCPIndex, typeDesc);
            defaultValue.setBooleanValue(boolValue);
            break;
        case TypeSignature.SIG_INT:
            valueCPIndex = dataInStream.readInt();
            IntegerCPEntry integerCPEntry = (IntegerCPEntry) constantPool.getCPEntry(valueCPIndex);
            defaultValue = new DefaultValue(typeDescCPIndex, typeDesc);
            defaultValue.setIntValue(integerCPEntry.getValue());
            break;
        case TypeSignature.SIG_FLOAT:
            valueCPIndex = dataInStream.readInt();
            FloatCPEntry floatCPEntry = (FloatCPEntry) constantPool.getCPEntry(valueCPIndex);
            defaultValue = new DefaultValue(typeDescCPIndex, typeDesc);
            defaultValue.setFloatValue(floatCPEntry.getValue());
            break;
        case TypeSignature.SIG_STRING:
            valueCPIndex = dataInStream.readInt();
            UTF8CPEntry stringCPEntry = (UTF8CPEntry) constantPool.getCPEntry(valueCPIndex);
            defaultValue = new DefaultValue(typeDescCPIndex, typeDesc);
            defaultValue.setStringValue(stringCPEntry.getValue());
            break;
        default:
            throw new ProgramFileFormatException("unknown default value type " + typeDesc);
    }
    return defaultValue;
}
Also used : UTF8CPEntry(org.ballerinalang.util.codegen.cpentries.UTF8CPEntry) ProgramFileFormatException(org.ballerinalang.util.exceptions.ProgramFileFormatException) IntegerCPEntry(org.ballerinalang.util.codegen.cpentries.IntegerCPEntry) FloatCPEntry(org.ballerinalang.util.codegen.cpentries.FloatCPEntry)

Example 9 with UTF8CPEntry

use of org.ballerinalang.util.codegen.cpentries.UTF8CPEntry in project ballerina by ballerina-lang.

the class ProgramFileReader method readPackageInfo.

private void readPackageInfo(DataInputStream dataInStream) throws IOException {
    PackageInfo packageInfo = new PackageInfo();
    // Read constant pool in the package.
    readConstantPool(dataInStream, packageInfo);
    int pkgNameCPIndex = dataInStream.readInt();
    UTF8CPEntry pkgNameCPEntry = (UTF8CPEntry) packageInfo.getCPEntry(pkgNameCPIndex);
    packageInfo.nameCPIndex = pkgNameCPIndex;
    packageInfo.pkgPath = pkgNameCPEntry.getValue();
    packageInfo.setProgramFile(programFile);
    programFile.addPackageInfo(packageInfo.pkgPath, packageInfo);
    // Read struct info entries
    readStructInfoEntries(dataInStream, packageInfo);
    // Read enum info entries
    readEnumInfoEntries(dataInStream, packageInfo);
    // Read connector info entries
    readConnectorInfoEntries(dataInStream, packageInfo);
    // Read service info entries
    readServiceInfoEntries(dataInStream, packageInfo);
    // Resolve user-defined type i.e. structs and connectors
    resolveUserDefinedTypes(packageInfo);
    // Read connector action info entries
    readConnectorActionInfoEntries(dataInStream, packageInfo);
    // Read resource info entries.
    readResourceInfoEntries(dataInStream, packageInfo);
    // Read constant info entries
    readConstantInfoEntries(dataInStream, packageInfo);
    // Read global var info entries
    readGlobalVarInfoEntries(dataInStream, packageInfo);
    // Read function info entries in the package
    readFunctionInfoEntries(dataInStream, packageInfo);
    // Read transformer info entries in the package
    readTransformerInfoEntries(dataInStream, packageInfo);
    // TODO Read annotation info entries
    // Resolve unresolved CP entries.
    resolveCPEntries();
    resolveConnectorMethodTables(packageInfo);
    // Read attribute info entries
    readAttributeInfoEntries(dataInStream, packageInfo, packageInfo);
    // Read instructions
    readInstructions(dataInStream, packageInfo);
    packageInfo.complete();
}
Also used : UTF8CPEntry(org.ballerinalang.util.codegen.cpentries.UTF8CPEntry)

Example 10 with UTF8CPEntry

use of org.ballerinalang.util.codegen.cpentries.UTF8CPEntry in project ballerina by ballerina-lang.

the class ProgramFileReader method getAttributeInfo.

private AttributeInfo getAttributeInfo(DataInputStream dataInStream, ConstantPool constantPool) throws IOException {
    int attribNameCPIndex = dataInStream.readInt();
    UTF8CPEntry attribNameCPEntry = (UTF8CPEntry) constantPool.getCPEntry(attribNameCPIndex);
    AttributeInfo.Kind attribKind = AttributeInfo.Kind.fromString(attribNameCPEntry.getValue());
    if (attribKind == null) {
        throw new ProgramFileFormatException("unknown attribute kind " + attribNameCPEntry.getValue());
    }
    switch(attribKind) {
        case CODE_ATTRIBUTE:
            CodeAttributeInfo codeAttributeInfo = new CodeAttributeInfo();
            codeAttributeInfo.setAttributeNameIndex(attribNameCPIndex);
            codeAttributeInfo.setCodeAddrs(dataInStream.readInt());
            codeAttributeInfo.setMaxLongLocalVars(dataInStream.readUnsignedShort());
            codeAttributeInfo.setMaxDoubleLocalVars(dataInStream.readShort());
            codeAttributeInfo.setMaxStringLocalVars(dataInStream.readShort());
            codeAttributeInfo.setMaxIntLocalVars(dataInStream.readShort());
            codeAttributeInfo.setMaxByteLocalVars(dataInStream.readShort());
            codeAttributeInfo.setMaxRefLocalVars(dataInStream.readShort());
            codeAttributeInfo.setMaxLongRegs(dataInStream.readShort());
            codeAttributeInfo.setMaxDoubleRegs(dataInStream.readShort());
            codeAttributeInfo.setMaxStringRegs(dataInStream.readShort());
            codeAttributeInfo.setMaxIntRegs(dataInStream.readShort());
            codeAttributeInfo.setMaxByteRegs(dataInStream.readShort());
            codeAttributeInfo.setMaxRefRegs(dataInStream.readShort());
            return codeAttributeInfo;
        case VARIABLE_TYPE_COUNT_ATTRIBUTE:
            VarTypeCountAttributeInfo varCountAttributeInfo = new VarTypeCountAttributeInfo(attribNameCPIndex);
            varCountAttributeInfo.setMaxLongVars(dataInStream.readShort());
            varCountAttributeInfo.setMaxDoubleVars(dataInStream.readShort());
            varCountAttributeInfo.setMaxStringVars(dataInStream.readShort());
            varCountAttributeInfo.setMaxIntVars(dataInStream.readShort());
            varCountAttributeInfo.setMaxByteVars(dataInStream.readShort());
            varCountAttributeInfo.setMaxRefVars(dataInStream.readShort());
            return varCountAttributeInfo;
        case ERROR_TABLE:
            ErrorTableAttributeInfo tableAttributeInfo = new ErrorTableAttributeInfo(attribNameCPIndex);
            int tableEntryCount = dataInStream.readShort();
            for (int i = 0; i < tableEntryCount; i++) {
                int ipFrom = dataInStream.readInt();
                int ipTo = dataInStream.readInt();
                int ipTarget = dataInStream.readInt();
                int priority = dataInStream.readInt();
                int errorStructCPIndex = dataInStream.readInt();
                ErrorTableEntry tableEntry = new ErrorTableEntry(ipFrom, ipTo, ipTarget, priority, errorStructCPIndex);
                if (errorStructCPIndex != -1) {
                    StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) constantPool.getCPEntry(errorStructCPIndex);
                    tableEntry.setError((StructInfo) structureRefCPEntry.getStructureTypeInfo());
                }
                tableAttributeInfo.addErrorTableEntry(tableEntry);
            }
            return tableAttributeInfo;
        case LOCAL_VARIABLES_ATTRIBUTE:
            LocalVariableAttributeInfo localVarAttrInfo = new LocalVariableAttributeInfo(attribNameCPIndex);
            int localVarInfoCount = dataInStream.readShort();
            for (int i = 0; i < localVarInfoCount; i++) {
                LocalVariableInfo localVariableInfo = getLocalVariableInfo(dataInStream, constantPool);
                localVarAttrInfo.addLocalVarInfo(localVariableInfo);
            }
            return localVarAttrInfo;
        case LINE_NUMBER_TABLE_ATTRIBUTE:
            LineNumberTableAttributeInfo lnNoTblAttrInfo = new LineNumberTableAttributeInfo(attribNameCPIndex);
            int lineNoInfoCount = dataInStream.readShort();
            for (int i = 0; i < lineNoInfoCount; i++) {
                LineNumberInfo lineNumberInfo = getLineNumberInfo(dataInStream, constantPool);
                lnNoTblAttrInfo.addLineNumberInfo(lineNumberInfo);
            }
            return lnNoTblAttrInfo;
        case DEFAULT_VALUE_ATTRIBUTE:
            DefaultValue defaultValue = getDefaultValue(dataInStream, constantPool);
            DefaultValueAttributeInfo defaultValAttrInfo = new DefaultValueAttributeInfo(attribNameCPIndex, defaultValue);
            return defaultValAttrInfo;
        case PARAMETER_DEFAULTS_ATTRIBUTE:
            ParamDefaultValueAttributeInfo paramDefaultValAttrInfo = new ParamDefaultValueAttributeInfo(attribNameCPIndex);
            int paramDefaultsInfoCount = dataInStream.readShort();
            for (int i = 0; i < paramDefaultsInfoCount; i++) {
                DefaultValue paramDefaultValue = getDefaultValue(dataInStream, constantPool);
                paramDefaultValAttrInfo.addParamDefaultValueInfo(paramDefaultValue);
            }
            return paramDefaultValAttrInfo;
        default:
            throw new ProgramFileFormatException("unsupported attribute kind " + attribNameCPEntry.getValue());
    }
}
Also used : VarTypeCountAttributeInfo(org.ballerinalang.util.codegen.attributes.VarTypeCountAttributeInfo) LineNumberTableAttributeInfo(org.ballerinalang.util.codegen.attributes.LineNumberTableAttributeInfo) ProgramFileFormatException(org.ballerinalang.util.exceptions.ProgramFileFormatException) UTF8CPEntry(org.ballerinalang.util.codegen.cpentries.UTF8CPEntry) ParamDefaultValueAttributeInfo(org.ballerinalang.util.codegen.attributes.ParamDefaultValueAttributeInfo) LocalVariableAttributeInfo(org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo) ErrorTableAttributeInfo(org.ballerinalang.util.codegen.attributes.ErrorTableAttributeInfo) LineNumberTableAttributeInfo(org.ballerinalang.util.codegen.attributes.LineNumberTableAttributeInfo) CodeAttributeInfo(org.ballerinalang.util.codegen.attributes.CodeAttributeInfo) DefaultValueAttributeInfo(org.ballerinalang.util.codegen.attributes.DefaultValueAttributeInfo) VarTypeCountAttributeInfo(org.ballerinalang.util.codegen.attributes.VarTypeCountAttributeInfo) AttributeInfo(org.ballerinalang.util.codegen.attributes.AttributeInfo) ParamDefaultValueAttributeInfo(org.ballerinalang.util.codegen.attributes.ParamDefaultValueAttributeInfo) LocalVariableAttributeInfo(org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo) ParamDefaultValueAttributeInfo(org.ballerinalang.util.codegen.attributes.ParamDefaultValueAttributeInfo) DefaultValueAttributeInfo(org.ballerinalang.util.codegen.attributes.DefaultValueAttributeInfo) ErrorTableAttributeInfo(org.ballerinalang.util.codegen.attributes.ErrorTableAttributeInfo) CodeAttributeInfo(org.ballerinalang.util.codegen.attributes.CodeAttributeInfo) StructureRefCPEntry(org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry)

Aggregations

UTF8CPEntry (org.ballerinalang.util.codegen.cpentries.UTF8CPEntry)19 WorkerDataChannelRefCPEntry (org.ballerinalang.util.codegen.cpentries.WorkerDataChannelRefCPEntry)4 ProgramFileFormatException (org.ballerinalang.util.exceptions.ProgramFileFormatException)4 ForkJoinCPEntry (org.ballerinalang.util.codegen.cpentries.ForkJoinCPEntry)3 TypeRefCPEntry (org.ballerinalang.util.codegen.cpentries.TypeRefCPEntry)3 NativeCallableUnit (org.ballerinalang.model.NativeCallableUnit)2 BStructType (org.ballerinalang.model.types.BStructType)2 BType (org.ballerinalang.model.types.BType)2 CodeAttributeInfo (org.ballerinalang.util.codegen.attributes.CodeAttributeInfo)2 ActionRefCPEntry (org.ballerinalang.util.codegen.cpentries.ActionRefCPEntry)2 FloatCPEntry (org.ballerinalang.util.codegen.cpentries.FloatCPEntry)2 FunctionRefCPEntry (org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry)2 IntegerCPEntry (org.ballerinalang.util.codegen.cpentries.IntegerCPEntry)2 StructureRefCPEntry (org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry)2 TransformerRefCPEntry (org.ballerinalang.util.codegen.cpentries.TransformerRefCPEntry)2 BLangRuntimeException (org.ballerinalang.util.exceptions.BLangRuntimeException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 BConnectorType (org.ballerinalang.model.types.BConnectorType)1 BEnumType (org.ballerinalang.model.types.BEnumType)1