Search in sources :

Example 1 with TypeRefCPEntry

use of org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry in project ballerina by ballerina-lang.

the class PackageInfoWriter method writeCP.

public static void writeCP(DataOutputStream dataOutStream, ConstantPoolEntry[] constPool) throws IOException {
    dataOutStream.writeInt(constPool.length);
    for (ConstantPoolEntry cpEntry : constPool) {
        // Emitting the kind of the constant pool entry.
        dataOutStream.writeByte(cpEntry.getEntryType().getValue());
        int nameCPIndex;
        switch(cpEntry.getEntryType()) {
            case CP_ENTRY_UTF8:
                String stringVal = ((UTF8CPEntry) cpEntry).getValue();
                if (stringVal != null) {
                    byte[] bytes = toUTF(stringVal);
                    dataOutStream.writeShort(bytes.length);
                    dataOutStream.write(bytes);
                } else {
                    // If the string value is null, we write the size as -1.
                    // This marks that the value followed by -1 size is a null value.
                    dataOutStream.writeShort(NULL_VALUE_FIELD_SIZE_TAG);
                }
                break;
            case CP_ENTRY_INTEGER:
                long longVal = ((IntegerCPEntry) cpEntry).getValue();
                dataOutStream.writeLong(longVal);
                break;
            case CP_ENTRY_FLOAT:
                double doubleVal = ((FloatCPEntry) cpEntry).getValue();
                dataOutStream.writeDouble(doubleVal);
                break;
            case CP_ENTRY_STRING:
                nameCPIndex = ((StringCPEntry) cpEntry).getStringCPIndex();
                dataOutStream.writeInt(nameCPIndex);
                break;
            case CP_ENTRY_PACKAGE:
                nameCPIndex = ((PackageRefCPEntry) cpEntry).nameCPIndex;
                dataOutStream.writeInt(nameCPIndex);
                break;
            case CP_ENTRY_FUNCTION_REF:
                FunctionRefCPEntry funcRefEntry = (FunctionRefCPEntry) cpEntry;
                dataOutStream.writeInt(funcRefEntry.packageCPIndex);
                dataOutStream.writeInt(funcRefEntry.nameCPIndex);
                break;
            case CP_ENTRY_ACTION_REF:
                ActionRefCPEntry actionRefEntry = (ActionRefCPEntry) cpEntry;
                dataOutStream.writeInt(actionRefEntry.getPackageCPIndex());
                dataOutStream.writeInt(actionRefEntry.getNameCPIndex());
                break;
            case CP_ENTRY_STRUCTURE_REF:
                StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) cpEntry;
                dataOutStream.writeInt(structureRefCPEntry.packageCPIndex);
                dataOutStream.writeInt(structureRefCPEntry.nameCPIndex);
                break;
            case CP_ENTRY_TYPE_REF:
                TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) cpEntry;
                dataOutStream.writeInt(typeRefCPEntry.typeSigCPIndex);
                break;
            case CP_ENTRY_FORK_JOIN:
                ForkJoinCPEntry forkJoinCPEntry = (ForkJoinCPEntry) cpEntry;
                dataOutStream.writeInt(forkJoinCPEntry.forkJoinInfoIndex);
                break;
            case CP_ENTRY_WRKR_DATA_CHNL_REF:
                WorkerDataChannelRefCPEntry workerDataChannelCPEntry = (WorkerDataChannelRefCPEntry) cpEntry;
                dataOutStream.writeInt(workerDataChannelCPEntry.getUniqueNameCPIndex());
                break;
            case CP_ENTRY_TRANSFORMER_REF:
                TransformerRefCPEntry transformerRefEntry = (TransformerRefCPEntry) cpEntry;
                dataOutStream.writeInt(transformerRefEntry.packageCPIndex);
                dataOutStream.writeInt(transformerRefEntry.nameCPIndex);
                break;
        }
    }
}
Also used : TransformerRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TransformerRefCPEntry) TypeRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry) ActionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.ActionRefCPEntry) FloatCPEntry(org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry) WorkerDataChannelRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry) ConstantPoolEntry(org.wso2.ballerinalang.programfile.cpentries.ConstantPoolEntry) UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) FunctionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.FunctionRefCPEntry) ForkJoinCPEntry(org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry) StructureRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry) IntegerCPEntry(org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry)

Example 2 with TypeRefCPEntry

use of org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry in project ballerina by ballerina-lang.

the class CodeGenerator method getOperands.

private Operand[] getOperands(BLangLock lockNode) {
    Operand[] operands = new Operand[(lockNode.lockVariables.size() * 2) + 1];
    int i = 0;
    operands[i++] = new Operand(lockNode.lockVariables.size());
    for (BVarSymbol varSymbol : lockNode.lockVariables) {
        int typeSigCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.getType().getDesc());
        TypeRefCPEntry typeRefCPEntry = new TypeRefCPEntry(typeSigCPIndex);
        operands[i++] = getOperand(currentPkgInfo.addCPEntry(typeRefCPEntry));
        operands[i++] = varSymbol.varIndex;
    }
    return operands;
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) TypeRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 3 with TypeRefCPEntry

use of org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry in project ballerina by ballerina-lang.

the class CodeGenerator method getTypeCPIndex.

/**
 * Get the constant pool entry index of a given type.
 *
 * @param type Type to get the constant pool entry index
 * @return constant pool entry index of the type
 */
private Operand getTypeCPIndex(BType type) {
    int typeSigCPIndex = addUTF8CPEntry(currentPkgInfo, type.getDesc());
    TypeRefCPEntry typeRefCPEntry = new TypeRefCPEntry(typeSigCPIndex);
    return getOperand(currentPkgInfo.addCPEntry(typeRefCPEntry));
}
Also used : TypeRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

TypeRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry)3 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)1 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)1 ActionRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.ActionRefCPEntry)1 ConstantPoolEntry (org.wso2.ballerinalang.programfile.cpentries.ConstantPoolEntry)1 FloatCPEntry (org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry)1 ForkJoinCPEntry (org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry)1 FunctionRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.FunctionRefCPEntry)1 IntegerCPEntry (org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry)1 StructureRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry)1 TransformerRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.TransformerRefCPEntry)1 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)1 WorkerDataChannelRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry)1