Search in sources :

Example 1 with Dependency

use of org.robovm.compiler.clazz.Dependency in project robovm by robovm.

the class DependencyGraph method add.

/**
     * Adds the specified {@link Clazz} to the graph after it has been compiled.
     * If {@code root == true} the class will be added to the root set and it as
     * well as its methods will always be reachable.
     */
public void add(Clazz clazz, boolean root) {
    reachableNodes.clear();
    ClassNode classNode = getClassNode(clazz.getInternalName());
    if (root) {
        roots.add(classNode);
    }
    ClazzInfo ci = clazz.getClazzInfo();
    for (Dependency dep : ci.getDependencies()) {
        if (dep instanceof InvokeMethodDependency) {
            InvokeMethodDependency mdep = (InvokeMethodDependency) dep;
            classNode.addEgde(getMethodNode(mdep), mdep.isWeak());
        } else if (dep instanceof SuperMethodDependency) {
            SuperMethodDependency mdep = (SuperMethodDependency) dep;
            classNode.addEgde(getMethodNode(mdep), mdep.isWeak());
        } else {
            classNode.addEgde(getClassNode(dep.getClassName()), dep.isWeak());
        }
    }
    for (MethodInfo mi : ci.getMethods()) {
        boolean strong = root || // Keep callback methods
        mi.isCallback() || // Keep class initializers
        (mi.isStatic() && "<clinit>".equals(mi.getName()) && "()V".equals(mi.getDesc())) || // in enum classes
        (ci.isEnum() && mi.isStatic() && "values".equals(mi.getName()) && mi.getDesc().equals("()[L" + clazz.getInternalName() + ";")) || // in Struct classes
        (ci.isStruct() && mi.isStatic() && "sizeOf".equals(mi.getName()) && "()I".equals(mi.getDesc()));
        MethodNode methodNode = getMethodNode(clazz, mi);
        classNode.addEgde(methodNode, !strong);
        methodNode.addEgde(classNode, false);
        for (Dependency dep : mi.getDependencies()) {
            if (dep instanceof InvokeMethodDependency) {
                InvokeMethodDependency mdep = (InvokeMethodDependency) dep;
                methodNode.addEgde(getMethodNode(mdep), mdep.isWeak());
            } else if (dep instanceof SuperMethodDependency) {
                // Reverse the dependency so that the method is strongly
                // linked if the super method is invoked.
                SuperMethodDependency mdep = (SuperMethodDependency) dep;
                getMethodNode(mdep).addEgde(methodNode, false);
            } else {
                methodNode.addEgde(getClassNode(dep.getClassName()), dep.isWeak());
            }
        }
    }
}
Also used : SuperMethodDependency(org.robovm.compiler.clazz.SuperMethodDependency) MethodInfo(org.robovm.compiler.clazz.MethodInfo) ClazzInfo(org.robovm.compiler.clazz.ClazzInfo) MethodDependency(org.robovm.compiler.clazz.MethodDependency) SuperMethodDependency(org.robovm.compiler.clazz.SuperMethodDependency) Dependency(org.robovm.compiler.clazz.Dependency) InvokeMethodDependency(org.robovm.compiler.clazz.InvokeMethodDependency) InvokeMethodDependency(org.robovm.compiler.clazz.InvokeMethodDependency)

Example 2 with Dependency

use of org.robovm.compiler.clazz.Dependency in project robovm by robovm.

the class AnnotationImplPluginTest method createAnnoImpl.

private File createAnnoImpl(Class<? extends Annotation> annoClass) {
    AnnotationImplPlugin plugin = new AnnotationImplPlugin();
    Clazz clazz = toClazz(annoClass);
    clazz.resetClazzInfo();
    plugin.beforeClass(config, clazz, new ModuleBuilder());
    assertFalse(clazz.getClazzInfo().getAllDependencies().isEmpty());
    Dependency dep = clazz.getClazzInfo().getAllDependencies().iterator().next();
    assertEquals(clazz.getInternalName() + "$Impl", dep.getClassName());
    final File implFile = new File(config.getGeneratedClassDir(clazz.getPath()), clazz.getInternalName() + "$Impl.class");
    assertTrue(implFile.exists());
    return implFile;
}
Also used : ModuleBuilder(org.robovm.compiler.ModuleBuilder) Clazz(org.robovm.compiler.clazz.Clazz) Dependency(org.robovm.compiler.clazz.Dependency) File(java.io.File)

Example 3 with Dependency

use of org.robovm.compiler.clazz.Dependency in project robovm by robovm.

the class ClassCompiler method mustCompile.

public boolean mustCompile(Clazz clazz) {
    File oFile = config.getOFile(clazz);
    if (!oFile.exists() || oFile.lastModified() < clazz.lastModified() || oFile.length() == 0) {
        return true;
    }
    ClazzInfo ci = clazz.getClazzInfo();
    if (ci == null) {
        return true;
    }
    Set<Dependency> dependencies = ci.getAllDependencies();
    for (Dependency dep : dependencies) {
        Clazz depClazz = config.getClazzes().load(dep.getClassName());
        if (depClazz == null) {
            if (dep.getPath() != null) {
                // depClazz was available the last time clazz was compiled but is now gone
                return true;
            }
        } else {
            if (dep.getPath() == null) {
                // depClazz was not available the last time clazz was compiled but is now available
                return true;
            }
            if (!dep.getPath().equals(depClazz.getPath().getFile().getAbsolutePath())) {
                // depClazz was located in another place the last time clazz was built
                return true;
            }
            if (depClazz.isInBootClasspath() != dep.isInBootClasspath()) {
                // depClazz has moved to/from the bootclasspath since the last time clazz was built
                return true;
            }
            if (depClazz.lastModified() > oFile.lastModified()) {
                // depClazz has been changed since the last time clazz was built 
                return true;
            }
        }
    }
    // and the dependencies regenerated.
    return dependencies.isEmpty();
}
Also used : Clazz(org.robovm.compiler.clazz.Clazz) ClazzInfo(org.robovm.compiler.clazz.ClazzInfo) Dependency(org.robovm.compiler.clazz.Dependency) ObjectFile(org.robovm.llvm.ObjectFile) File(java.io.File)

Aggregations

Dependency (org.robovm.compiler.clazz.Dependency)3 File (java.io.File)2 Clazz (org.robovm.compiler.clazz.Clazz)2 ClazzInfo (org.robovm.compiler.clazz.ClazzInfo)2 ModuleBuilder (org.robovm.compiler.ModuleBuilder)1 InvokeMethodDependency (org.robovm.compiler.clazz.InvokeMethodDependency)1 MethodDependency (org.robovm.compiler.clazz.MethodDependency)1 MethodInfo (org.robovm.compiler.clazz.MethodInfo)1 SuperMethodDependency (org.robovm.compiler.clazz.SuperMethodDependency)1 ObjectFile (org.robovm.llvm.ObjectFile)1