Search in sources :

Example 1 with InvokeMethodDependency

use of org.robovm.compiler.clazz.InvokeMethodDependency 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)

Aggregations

ClazzInfo (org.robovm.compiler.clazz.ClazzInfo)1 Dependency (org.robovm.compiler.clazz.Dependency)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