Search in sources :

Example 1 with ConstantPoolEntry

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

the class ProgramFileReader method resolveUserDefinedTypes.

private void resolveUserDefinedTypes(PackageInfo packageInfo) {
    // TODO Improve this. We should be able to this in a single pass.
    StructInfo[] structInfoEntries = packageInfo.getStructInfoEntries();
    for (StructInfo structInfo : structInfoEntries) {
        StructFieldInfo[] fieldInfoEntries = structInfo.getFieldInfoEntries();
        BStructType structType = structInfo.getType();
        BStructType.StructField[] structFields = new BStructType.StructField[fieldInfoEntries.length];
        for (int i = 0; i < fieldInfoEntries.length; i++) {
            // Get the BType from the type descriptor
            StructFieldInfo fieldInfo = fieldInfoEntries[i];
            String typeDesc = fieldInfo.getTypeDescriptor();
            BType fieldType = getBTypeFromDescriptor(typeDesc);
            fieldInfo.setFieldType(fieldType);
            // Create the StructField in the BStructType. This is required for the type equivalence algorithm
            BStructType.StructField structField = new BStructType.StructField(fieldType, fieldInfo.getName(), fieldInfo.flags);
            structFields[i] = structField;
        }
        VarTypeCountAttributeInfo attributeInfo = (VarTypeCountAttributeInfo) structInfo.getAttributeInfo(AttributeInfo.Kind.VARIABLE_TYPE_COUNT_ATTRIBUTE);
        structType.setFieldTypeCount(attributeInfo.getVarTypeCount());
        structType.setStructFields(structFields);
        // Resolve attached function signature
        int attachedFuncCount = structInfo.funcInfoEntries.size();
        BStructType.AttachedFunction[] attachedFunctions = new BStructType.AttachedFunction[attachedFuncCount];
        int count = 0;
        for (AttachedFunctionInfo attachedFuncInfo : structInfo.funcInfoEntries.values()) {
            BFunctionType funcType = getFunctionType(attachedFuncInfo.typeSignature, packageInfo);
            BStructType.AttachedFunction attachedFunction = new BStructType.AttachedFunction(attachedFuncInfo.name, funcType, attachedFuncInfo.flags);
            attachedFunctions[count++] = attachedFunction;
            if (structInfo.initializer == attachedFuncInfo) {
                structType.initializer = attachedFunction;
            } else if (structInfo.defaultsValuesInitFunc == attachedFuncInfo) {
                structType.defaultsValuesInitFunc = attachedFunction;
            }
        }
        structType.setAttachedFunctions(attachedFunctions);
    }
    for (ConstantPoolEntry cpEntry : unresolvedCPEntries) {
        switch(cpEntry.getEntryType()) {
            case CP_ENTRY_TYPE_REF:
                TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) cpEntry;
                String typeSig = typeRefCPEntry.getTypeSig();
                BType bType = getBTypeFromDescriptor(typeSig);
                typeRefCPEntry.setType(bType);
                break;
            default:
                break;
        }
    }
}
Also used : VarTypeCountAttributeInfo(org.ballerinalang.util.codegen.attributes.VarTypeCountAttributeInfo) TypeRefCPEntry(org.ballerinalang.util.codegen.cpentries.TypeRefCPEntry) BFunctionType(org.ballerinalang.model.types.BFunctionType) ConstantPoolEntry(org.ballerinalang.util.codegen.cpentries.ConstantPoolEntry) BStructType(org.ballerinalang.model.types.BStructType) BType(org.ballerinalang.model.types.BType)

Example 2 with ConstantPoolEntry

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

the class ProgramFileReader method readConstantPool.

private void readConstantPool(DataInputStream dataInStream, ConstantPool constantPool) throws IOException {
    int constantPoolSize = dataInStream.readInt();
    for (int i = 0; i < constantPoolSize; i++) {
        byte cpTag = dataInStream.readByte();
        ConstantPoolEntry.EntryType cpEntryType = ConstantPoolEntry.EntryType.values()[cpTag - 1];
        ConstantPoolEntry cpEntry = readCPEntry(dataInStream, constantPool, cpEntryType);
        constantPool.addCPEntry(cpEntry);
    }
}
Also used : ConstantPoolEntry(org.ballerinalang.util.codegen.cpentries.ConstantPoolEntry)

Example 3 with ConstantPoolEntry

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

Aggregations

ConstantPoolEntry (org.ballerinalang.util.codegen.cpentries.ConstantPoolEntry)3 BType (org.ballerinalang.model.types.BType)2 TypeRefCPEntry (org.ballerinalang.util.codegen.cpentries.TypeRefCPEntry)2 BFunctionType (org.ballerinalang.model.types.BFunctionType)1 BStructType (org.ballerinalang.model.types.BStructType)1 VarTypeCountAttributeInfo (org.ballerinalang.util.codegen.attributes.VarTypeCountAttributeInfo)1 FunctionRefCPEntry (org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry)1 StructureRefCPEntry (org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry)1 TransformerRefCPEntry (org.ballerinalang.util.codegen.cpentries.TransformerRefCPEntry)1