Search in sources :

Example 1 with CPInfo

use of org.eclipse.ceylon.langtools.classfile.ConstantPool.CPInfo in project ceylon by eclipse.

the class ClassTranslator method translate.

ConstantPool.CPInfo translate(ConstantPool.CPInfo cpInfo, Map<Object, Object> translations) {
    ConstantPool.CPInfo cpInfo2 = (ConstantPool.CPInfo) translations.get(cpInfo);
    if (cpInfo2 == null) {
        cpInfo2 = cpInfo.accept(this, translations);
        translations.put(cpInfo, cpInfo2);
    }
    return cpInfo2;
}
Also used : CPInfo(org.eclipse.ceylon.langtools.classfile.ConstantPool.CPInfo) CPInfo(org.eclipse.ceylon.langtools.classfile.ConstantPool.CPInfo)

Example 2 with CPInfo

use of org.eclipse.ceylon.langtools.classfile.ConstantPool.CPInfo in project ceylon by eclipse.

the class Java9Util method generateModuleDescriptor.

private static ClassFile generateModuleDescriptor(Java9ModuleDescriptor module) {
    CPInfo[] pool = new ConstantPool.CPInfo[1 + 7 + (module.imports.size() * 2) + (module.getPackagesSize() * 2) + (module.main != null ? 3 : 0)];
    ConstantPool constantPool = new ConstantPool(pool);
    int cp = 1;
    // 1: this_class name
    pool[cp++] = new ConstantPool.CONSTANT_Utf8_info("module-info");
    // 2: this_class
    pool[cp++] = new ConstantPool.CONSTANT_Class_info(constantPool, 1);
    // 3: module attr
    pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(Attribute.Module);
    // 4: module pkgs attr
    pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(Attribute.ModulePackages);
    // 5: version
    pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(module.version);
    // 6: module name
    pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(module.name);
    // 7: module info
    pool[cp++] = new ConstantPool.CONSTANT_Module_info(constantPool, 6);
    if (module.main != null) {
        // 8: main attr
        pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(Attribute.ModuleMainClass);
        // 9: main class name
        pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(module.main.replace('.', '/'));
        // 10: main class
        pool[cp++] = new ConstantPool.CONSTANT_Class_info(constantPool, 9);
    }
    int i = 0;
    // now imports
    Module_attribute.RequiresEntry[] requires = new Module_attribute.RequiresEntry[module.imports.size()];
    for (Java9ModuleImport imp : module.imports) {
        pool[cp] = new ConstantPool.CONSTANT_Utf8_info(imp.name);
        pool[cp + 1] = new ConstantPool.CONSTANT_Module_info(constantPool, cp);
        int flag = 0;
        if (imp.exported)
            flag |= Module_attribute.ACC_TRANSITIVE;
        // FIXME: add version info!
        requires[i] = new Module_attribute.RequiresEntry(cp + 1, flag, 0);
        i++;
        cp += 2;
    }
    Module_attribute.ExportsEntry[] exports = new Module_attribute.ExportsEntry[module.exportedPackages.size()];
    i = 0;
    int[] modulePackages = new int[module.exportedPackages.size() + module.concealedPackages.size()];
    int m = 0;
    for (String pkg : module.exportedPackages) {
        pool[cp] = new ConstantPool.CONSTANT_Utf8_info(pkg.replace('.', '/'));
        pool[cp + 1] = new ConstantPool.CONSTANT_Package_info(constantPool, cp);
        exports[i++] = new Module_attribute.ExportsEntry(cp + 1, 0, new int[0]);
        modulePackages[m++] = cp + 1;
        cp += 2;
    }
    for (String pkg : module.concealedPackages) {
        pool[cp] = new ConstantPool.CONSTANT_Utf8_info(pkg.replace('.', '/'));
        pool[cp + 1] = new ConstantPool.CONSTANT_Package_info(constantPool, cp);
        modulePackages[m++] = cp + 1;
        cp += 2;
    }
    Attribute[] attributesArray = new Attribute[2 + (module.main != null ? 1 : 0)];
    attributesArray[0] = new Module_attribute(3, // module name index
    7, // flags
    0, // version
    5, requires, exports, new Module_attribute.OpensEntry[0], new int[0], new Module_attribute.ProvidesEntry[0]);
    attributesArray[1] = new ModulePackages_attribute(4, modulePackages);
    if (module.main != null)
        attributesArray[2] = new ModuleMainClass_attribute(8, 10);
    Attributes attributes = new Attributes(constantPool, attributesArray);
    return new ClassFile(org.eclipse.ceylon.langtools.tools.javac.jvm.ClassFile.JAVA_MAGIC, org.eclipse.ceylon.langtools.tools.javac.jvm.ClassFile.Version.V53.minor, org.eclipse.ceylon.langtools.tools.javac.jvm.ClassFile.Version.V53.major, constantPool, new org.eclipse.ceylon.langtools.classfile.AccessFlags(org.eclipse.ceylon.langtools.classfile.AccessFlags.ACC_MODULE), 2, 0, new int[0], new org.eclipse.ceylon.langtools.classfile.Field[0], new org.eclipse.ceylon.langtools.classfile.Method[0], attributes);
}
Also used : Attribute(org.eclipse.ceylon.langtools.classfile.Attribute) Attributes(org.eclipse.ceylon.langtools.classfile.Attributes) Module_attribute(org.eclipse.ceylon.langtools.classfile.Module_attribute) ModuleMainClass_attribute(org.eclipse.ceylon.langtools.classfile.ModuleMainClass_attribute) ClassFile(org.eclipse.ceylon.langtools.classfile.ClassFile) CPInfo(org.eclipse.ceylon.langtools.classfile.ConstantPool.CPInfo) ConstantPool(org.eclipse.ceylon.langtools.classfile.ConstantPool) ModulePackages_attribute(org.eclipse.ceylon.langtools.classfile.ModulePackages_attribute)

Example 3 with CPInfo

use of org.eclipse.ceylon.langtools.classfile.ConstantPool.CPInfo in project ceylon by eclipse.

the class ClassTranslator method translate.

ConstantPool translate(ConstantPool cp, Map<Object, Object> translations) {
    ConstantPool cp2 = (ConstantPool) translations.get(cp);
    if (cp2 == null) {
        ConstantPool.CPInfo[] pool2 = new ConstantPool.CPInfo[cp.size()];
        boolean eq = true;
        for (int i = 0; i < cp.size(); ) {
            ConstantPool.CPInfo cpInfo;
            try {
                cpInfo = cp.get(i);
            } catch (ConstantPool.InvalidIndex e) {
                throw new IllegalStateException(e);
            }
            ConstantPool.CPInfo cpInfo2 = translate(cpInfo, translations);
            eq &= (cpInfo == cpInfo2);
            pool2[i] = cpInfo2;
            if (cpInfo.getTag() != cpInfo2.getTag())
                throw new IllegalStateException();
            i += cpInfo.size();
        }
        if (eq)
            cp2 = cp;
        else
            cp2 = new ConstantPool(pool2);
        translations.put(cp, cp2);
    }
    return cp2;
}
Also used : CPInfo(org.eclipse.ceylon.langtools.classfile.ConstantPool.CPInfo) CPInfo(org.eclipse.ceylon.langtools.classfile.ConstantPool.CPInfo)

Aggregations

CPInfo (org.eclipse.ceylon.langtools.classfile.ConstantPool.CPInfo)3 Attribute (org.eclipse.ceylon.langtools.classfile.Attribute)1 Attributes (org.eclipse.ceylon.langtools.classfile.Attributes)1 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)1 ConstantPool (org.eclipse.ceylon.langtools.classfile.ConstantPool)1 ModuleMainClass_attribute (org.eclipse.ceylon.langtools.classfile.ModuleMainClass_attribute)1 ModulePackages_attribute (org.eclipse.ceylon.langtools.classfile.ModulePackages_attribute)1 Module_attribute (org.eclipse.ceylon.langtools.classfile.Module_attribute)1