Search in sources :

Example 1 with InterfaceTypeUse

use of org.abs_models.frontend.ast.InterfaceTypeUse in project abstools by abstools.

the class ClassGenerator method generateExports.

private void generateExports() {
    ecs.println("-export([get_val_internal/2,set_val_internal/3,init_internal/0,get_state_for_modelapi/1,implemented_interfaces/0,exported/0]).");
    ecs.println("-compile(export_all).");
    ecs.println();
    HashSet<MethodSig> callable_sigs = new HashSet<>();
    HashSet<InterfaceDecl> visited = new HashSet<>();
    for (InterfaceTypeUse i : classDecl.getImplementedInterfaceUseList()) {
        visited.add((InterfaceDecl) i.getDecl());
    }
    while (!visited.isEmpty()) {
        InterfaceDecl id = visited.iterator().next();
        visited.remove(id);
        for (MethodSig ms : id.getBodyList()) {
            if (ms.isHTTPCallable()) {
                callable_sigs.add(ms);
            }
        }
        for (InterfaceTypeUse i : id.getExtendedInterfaceUseList()) {
            visited.add((InterfaceDecl) i.getDecl());
        }
    }
    ecs.print("implemented_interfaces() -> [ ");
    String separator = "";
    for (InterfaceDecl i : classDecl.getSuperTypes()) {
        ecs.format("%s<<\"%s\">>", separator, i.getName());
        separator = ", ";
    }
    ecs.println(" ].");
    ecs.println();
    ecs.print("exported() -> #{ ");
    boolean first = true;
    for (MethodSig ms : callable_sigs) {
        if (ms.isHTTPCallable()) {
            if (!first)
                ecs.print(", ");
            first = false;
            ecs.print("<<\"" + ms.getName() + "\">> => { ");
            ecs.print("'m_" + ms.getName() + "'");
            ecs.print(", ");
            ecs.print("<<\"" + ms.getReturnType().getType().toString() + "\">>");
            ecs.print(", ");
            ecs.print("[ ");
            boolean innerfirst = true;
            for (ParamDecl p : ms.getParamList()) {
                // ABS type, and ABS type arguments (if present)
                if (!innerfirst)
                    ecs.print(", ");
                innerfirst = false;
                ecs.print("{ ");
                ecs.print("<<\"" + p.getName() + "\">>, ");
                ecs.print("<<\"" + p.getType().toString() + "\">>, ");
                generateParameterDescription(p.getType());
                ecs.print(" }");
            }
            ecs.print("] ");
            ecs.print("}");
        }
    }
    ecs.println(" }.");
    ecs.println();
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) ParamDecl(org.abs_models.frontend.ast.ParamDecl) InterfaceTypeUse(org.abs_models.frontend.ast.InterfaceTypeUse) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) HashSet(java.util.HashSet)

Example 2 with InterfaceTypeUse

use of org.abs_models.frontend.ast.InterfaceTypeUse in project abstools by abstools.

the class ReachabilityInformation method isReachable.

/**
 * checks if the method is reachable. It looks at the class name
 * and all the interface names that are directly or indirectly
 * implemented by the method's class
 * @param method
 * @return true if method is reachable, false otherwise
 */
public boolean isReachable(MethodImpl method) {
    ClassDecl clazz = obtainOwnerClass(method);
    boolean reachable = false;
    if (clazz != null) {
        List<InterfaceTypeUse> interfaces = clazz.getImplementedInterfaceUseList();
        Iterator<InterfaceTypeUse> it = interfaces.iterator();
        // checks if the method is reachable with its class name
        reachable = reachableMethods.contains(getMethodId(clazz, method.getMethodSig()));
        // implemented by its class
        while (!reachable && it.hasNext()) reachable = isReachable(it.next(), method.getMethodSig());
        return reachable;
    } else
        return false;
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) InterfaceTypeUse(org.abs_models.frontend.ast.InterfaceTypeUse)

Example 3 with InterfaceTypeUse

use of org.abs_models.frontend.ast.InterfaceTypeUse in project abstools by abstools.

the class ClassDeclGenerator method generateClassHeader.

private void generateClassHeader() {
    stream.print("public ");
    if (!decl.isForeign())
        stream.print("final ");
    stream.print("class " + className + " extends " + ABSObject.class.getName() + " implements " + ABSClass.class.getName());
    for (InterfaceTypeUse use : decl.getImplementedInterfaceUses()) {
        String iname = JavaBackend.getQualifiedString(((InterfaceType) use.getType()).getDecl());
        stream.print(", " + iname);
    }
}
Also used : InterfaceTypeUse(org.abs_models.frontend.ast.InterfaceTypeUse)

Aggregations

InterfaceTypeUse (org.abs_models.frontend.ast.InterfaceTypeUse)3 HashSet (java.util.HashSet)1 ClassDecl (org.abs_models.frontend.ast.ClassDecl)1 InterfaceDecl (org.abs_models.frontend.ast.InterfaceDecl)1 MethodSig (org.abs_models.frontend.ast.MethodSig)1 ParamDecl (org.abs_models.frontend.ast.ParamDecl)1