Search in sources :

Example 1 with StructureRefCPEntry

use of org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry 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)

Example 2 with StructureRefCPEntry

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

the class ProgramFileReader method resolveConnectorMethodTables.

private void resolveConnectorMethodTables(PackageInfo packageInfo) {
    ConnectorInfo[] connectorInfoEntries = packageInfo.getConnectorInfoEntries();
    for (ConnectorInfo connectorInfo : connectorInfoEntries) {
        BConnectorType connectorType = connectorInfo.getType();
        VarTypeCountAttributeInfo attributeInfo = (VarTypeCountAttributeInfo) connectorInfo.getAttributeInfo(AttributeInfo.Kind.VARIABLE_TYPE_COUNT_ATTRIBUTE);
        connectorType.setFieldTypeCount(attributeInfo.getVarTypeCount());
        Map<Integer, Integer> methodTableInteger = connectorInfo.getMethodTableIndex();
        Map<BConnectorType, ConnectorInfo> methodTableType = new HashMap<>();
        for (Integer key : methodTableInteger.keySet()) {
            int keyType = methodTableInteger.get(key);
            TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) packageInfo.getCPEntry(key);
            StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) packageInfo.getCPEntry(keyType);
            ConnectorInfo connectorInfoType = (ConnectorInfo) structureRefCPEntry.getStructureTypeInfo();
            methodTableType.put((BConnectorType) typeRefCPEntry.getType(), connectorInfoType);
        }
        connectorInfo.setMethodTableType(methodTableType);
        for (ActionInfo actionInfo : connectorInfo.getActionInfoEntries()) {
            setCallableUnitSignature(actionInfo, actionInfo.getSignature(), packageInfo);
        }
    }
}
Also used : VarTypeCountAttributeInfo(org.ballerinalang.util.codegen.attributes.VarTypeCountAttributeInfo) HashMap(java.util.HashMap) TypeRefCPEntry(org.ballerinalang.util.codegen.cpentries.TypeRefCPEntry) BConnectorType(org.ballerinalang.model.types.BConnectorType) StructureRefCPEntry(org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry)

Example 3 with StructureRefCPEntry

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

the class ProgramFileReader method readCPEntry.

private ConstantPoolEntry readCPEntry(DataInputStream dataInStream, ConstantPool constantPool, ConstantPoolEntry.EntryType cpEntryType) throws IOException {
    int cpIndex;
    int pkgCPIndex;
    UTF8CPEntry utf8CPEntry;
    PackageRefCPEntry packageRefCPEntry;
    Optional<PackageInfo> packageInfoOptional;
    switch(cpEntryType) {
        case CP_ENTRY_UTF8:
            short length = dataInStream.readShort();
            String strValue = null;
            // Therefore we read the UTF value only if the length >= 0.
            if (length >= 0) {
                strValue = dataInStream.readUTF();
            }
            return new UTF8CPEntry(strValue);
        case CP_ENTRY_INTEGER:
            long longVal = dataInStream.readLong();
            return new IntegerCPEntry(longVal);
        case CP_ENTRY_FLOAT:
            double doubleVal = dataInStream.readDouble();
            return new FloatCPEntry(doubleVal);
        case CP_ENTRY_STRING:
            cpIndex = dataInStream.readInt();
            utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
            return new StringCPEntry(cpIndex, utf8CPEntry.getValue());
        case CP_ENTRY_PACKAGE:
            cpIndex = dataInStream.readInt();
            utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
            return new PackageRefCPEntry(cpIndex, utf8CPEntry.getValue());
        case CP_ENTRY_FUNCTION_REF:
            pkgCPIndex = dataInStream.readInt();
            packageRefCPEntry = (PackageRefCPEntry) constantPool.getCPEntry(pkgCPIndex);
            cpIndex = dataInStream.readInt();
            utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
            String funcName = utf8CPEntry.getValue();
            FunctionRefCPEntry functionRefCPEntry = new FunctionRefCPEntry(pkgCPIndex, packageRefCPEntry.getPackageName(), cpIndex, funcName);
            // Find the functionInfo
            packageInfoOptional = Optional.ofNullable(programFile.getPackageInfo(packageRefCPEntry.getPackageName()));
            Optional<FunctionInfo> funcInfoOptional = packageInfoOptional.map(packageInfo -> packageInfo.getFunctionInfo(funcName));
            if (!funcInfoOptional.isPresent()) {
                // This must reference to the current package and the current package is not been read yet.
                // Therefore we add this to the unresolved CP Entry list.
                unresolvedCPEntries.add(functionRefCPEntry);
                return functionRefCPEntry;
            }
            functionRefCPEntry.setFunctionInfo(funcInfoOptional.get());
            return functionRefCPEntry;
        case CP_ENTRY_TRANSFORMER_REF:
            pkgCPIndex = dataInStream.readInt();
            packageRefCPEntry = (PackageRefCPEntry) constantPool.getCPEntry(pkgCPIndex);
            cpIndex = dataInStream.readInt();
            utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
            String transformerName = utf8CPEntry.getValue();
            TransformerRefCPEntry transformerRefCPEntry = new TransformerRefCPEntry(pkgCPIndex, packageRefCPEntry.getPackageName(), cpIndex, transformerName);
            // Find the transformerInfo
            packageInfoOptional = Optional.ofNullable(programFile.getPackageInfo(packageRefCPEntry.getPackageName()));
            Optional<TransformerInfo> transInfoOptional = packageInfoOptional.map(packageInfo -> packageInfo.getTransformerInfo(transformerName));
            if (!transInfoOptional.isPresent()) {
                // This must reference to the current package and the current package is not been read yet.
                // Therefore we add this to the unresolved CP Entry list.
                unresolvedCPEntries.add(transformerRefCPEntry);
                return transformerRefCPEntry;
            }
            transformerRefCPEntry.setTransformerInfo(transInfoOptional.get());
            return transformerRefCPEntry;
        case CP_ENTRY_ACTION_REF:
            pkgCPIndex = dataInStream.readInt();
            packageRefCPEntry = (PackageRefCPEntry) constantPool.getCPEntry(pkgCPIndex);
            cpIndex = dataInStream.readInt();
            UTF8CPEntry nameCPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
            String actionName = nameCPEntry.getValue();
            return new ActionRefCPEntry(pkgCPIndex, packageRefCPEntry.getPackageName(), cpIndex, actionName);
        case CP_ENTRY_STRUCTURE_REF:
            pkgCPIndex = dataInStream.readInt();
            packageRefCPEntry = (PackageRefCPEntry) constantPool.getCPEntry(pkgCPIndex);
            cpIndex = dataInStream.readInt();
            utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
            StructureRefCPEntry structureRefCPEntry = new StructureRefCPEntry(pkgCPIndex, packageRefCPEntry.getPackageName(), cpIndex, utf8CPEntry.getValue());
            packageInfoOptional = Optional.ofNullable(programFile.getPackageInfo(packageRefCPEntry.getPackageName()));
            Optional<StructureTypeInfo> structInfoOptional = packageInfoOptional.map(packageInfo -> packageInfo.getStructureTypeInfo(utf8CPEntry.getValue()));
            if (!structInfoOptional.isPresent()) {
                // This must reference to the current package and the current package is not been read yet.
                // Therefore we add this to the unresolved CP Entry list.
                unresolvedCPEntries.add(structureRefCPEntry);
                return structureRefCPEntry;
            }
            structureRefCPEntry.setStructureTypeInfo(structInfoOptional.get());
            return structureRefCPEntry;
        case CP_ENTRY_TYPE_REF:
            int typeSigCPIndex = dataInStream.readInt();
            utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(typeSigCPIndex);
            TypeRefCPEntry typeRefCPEntry = new TypeRefCPEntry(typeSigCPIndex, utf8CPEntry.getValue());
            unresolvedCPEntries.add(typeRefCPEntry);
            return typeRefCPEntry;
        case CP_ENTRY_FORK_JOIN:
            int forkJoinCPIndex = dataInStream.readInt();
            return new ForkJoinCPEntry(forkJoinCPIndex);
        case CP_ENTRY_WRKR_DATA_CHNL_REF:
            int uniqueNameCPIndex = dataInStream.readInt();
            UTF8CPEntry wrkrDtChnlTypesSigCPEntry = (UTF8CPEntry) constantPool.getCPEntry(uniqueNameCPIndex);
            return new WorkerDataChannelRefCPEntry(uniqueNameCPIndex, wrkrDtChnlTypesSigCPEntry.getValue());
        default:
            throw new ProgramFileFormatException("invalid constant pool entry " + cpEntryType.getValue());
    }
}
Also used : StringCPEntry(org.ballerinalang.util.codegen.cpentries.StringCPEntry) ProgramFileFormatException(org.ballerinalang.util.exceptions.ProgramFileFormatException) UTF8CPEntry(org.ballerinalang.util.codegen.cpentries.UTF8CPEntry) ForkJoinCPEntry(org.ballerinalang.util.codegen.cpentries.ForkJoinCPEntry) PackageRefCPEntry(org.ballerinalang.util.codegen.cpentries.PackageRefCPEntry) TransformerRefCPEntry(org.ballerinalang.util.codegen.cpentries.TransformerRefCPEntry) TypeRefCPEntry(org.ballerinalang.util.codegen.cpentries.TypeRefCPEntry) ActionRefCPEntry(org.ballerinalang.util.codegen.cpentries.ActionRefCPEntry) FloatCPEntry(org.ballerinalang.util.codegen.cpentries.FloatCPEntry) WorkerDataChannelRefCPEntry(org.ballerinalang.util.codegen.cpentries.WorkerDataChannelRefCPEntry) FunctionRefCPEntry(org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry) StructureRefCPEntry(org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry) IntegerCPEntry(org.ballerinalang.util.codegen.cpentries.IntegerCPEntry)

Example 4 with StructureRefCPEntry

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

the class ProgramFileReader method resolveCPEntries.

private void resolveCPEntries() {
    for (ConstantPoolEntry cpEntry : unresolvedCPEntries) {
        PackageInfo packageInfo;
        StructureRefCPEntry structureRefCPEntry;
        switch(cpEntry.getEntryType()) {
            case CP_ENTRY_FUNCTION_REF:
                FunctionRefCPEntry funcRefCPEntry = (FunctionRefCPEntry) cpEntry;
                packageInfo = programFile.getPackageInfo(funcRefCPEntry.getPackagePath());
                FunctionInfo functionInfo = packageInfo.getFunctionInfo(funcRefCPEntry.getFunctionName());
                funcRefCPEntry.setFunctionInfo(functionInfo);
                break;
            case CP_ENTRY_STRUCTURE_REF:
                structureRefCPEntry = (StructureRefCPEntry) cpEntry;
                packageInfo = programFile.getPackageInfo(structureRefCPEntry.getPackagePath());
                StructureTypeInfo structureTypeInfo = packageInfo.getStructureTypeInfo(structureRefCPEntry.getStructureName());
                structureRefCPEntry.setStructureTypeInfo(structureTypeInfo);
                break;
            case CP_ENTRY_TYPE_REF:
                TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) cpEntry;
                String typeSig = typeRefCPEntry.getTypeSig();
                BType bType = getBTypeFromDescriptor(typeSig);
                typeRefCPEntry.setType(bType);
                break;
            case CP_ENTRY_TRANSFORMER_REF:
                TransformerRefCPEntry transformerRefCPEntry = (TransformerRefCPEntry) cpEntry;
                packageInfo = programFile.getPackageInfo(transformerRefCPEntry.getPackagePath());
                TransformerInfo transformerInfo = packageInfo.getTransformerInfo(transformerRefCPEntry.getTransformerName());
                transformerRefCPEntry.setTransformerInfo(transformerInfo);
                break;
            default:
                break;
        }
    }
}
Also used : FunctionRefCPEntry(org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry) TransformerRefCPEntry(org.ballerinalang.util.codegen.cpentries.TransformerRefCPEntry) TypeRefCPEntry(org.ballerinalang.util.codegen.cpentries.TypeRefCPEntry) BType(org.ballerinalang.model.types.BType) StructureRefCPEntry(org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry) ConstantPoolEntry(org.ballerinalang.util.codegen.cpentries.ConstantPoolEntry)

Example 5 with StructureRefCPEntry

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

the class CPU method createNewConnector.

private static void createNewConnector(WorkerExecutionContext ctx, int[] operands, WorkerData sf) {
    int cpIndex = operands[0];
    int i = operands[1];
    StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) ctx.constPool[cpIndex];
    ConnectorInfo connectorInfo = (ConnectorInfo) structureRefCPEntry.getStructureTypeInfo();
    BConnector bConnector = new BConnector(connectorInfo.getType());
    sf.refRegs[i] = bConnector;
}
Also used : BConnector(org.ballerinalang.model.values.BConnector) ConnectorInfo(org.ballerinalang.util.codegen.ConnectorInfo) StructureRefCPEntry(org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry)

Aggregations

StructureRefCPEntry (org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry)6 TypeRefCPEntry (org.ballerinalang.util.codegen.cpentries.TypeRefCPEntry)3 VarTypeCountAttributeInfo (org.ballerinalang.util.codegen.attributes.VarTypeCountAttributeInfo)2 FunctionRefCPEntry (org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry)2 TransformerRefCPEntry (org.ballerinalang.util.codegen.cpentries.TransformerRefCPEntry)2 UTF8CPEntry (org.ballerinalang.util.codegen.cpentries.UTF8CPEntry)2 ProgramFileFormatException (org.ballerinalang.util.exceptions.ProgramFileFormatException)2 HashMap (java.util.HashMap)1 BConnectorType (org.ballerinalang.model.types.BConnectorType)1 BType (org.ballerinalang.model.types.BType)1 BConnector (org.ballerinalang.model.values.BConnector)1 BStruct (org.ballerinalang.model.values.BStruct)1 ConnectorInfo (org.ballerinalang.util.codegen.ConnectorInfo)1 StructInfo (org.ballerinalang.util.codegen.StructInfo)1 AttributeInfo (org.ballerinalang.util.codegen.attributes.AttributeInfo)1 CodeAttributeInfo (org.ballerinalang.util.codegen.attributes.CodeAttributeInfo)1 DefaultValueAttributeInfo (org.ballerinalang.util.codegen.attributes.DefaultValueAttributeInfo)1 ErrorTableAttributeInfo (org.ballerinalang.util.codegen.attributes.ErrorTableAttributeInfo)1 LineNumberTableAttributeInfo (org.ballerinalang.util.codegen.attributes.LineNumberTableAttributeInfo)1 LocalVariableAttributeInfo (org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo)1