Search in sources :

Example 1 with InterfaceDecl

use of org.abs_models.frontend.ast.InterfaceDecl 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 InterfaceDecl

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

the class ASTBasedABSTestRunnerGenerator method generateImportsAST.

private List<Import> generateImportsAST() {
    List<Import> imports = new List<>();
    Set<String> mn = new HashSet<>();
    Set<String> qn = new HashSet<>();
    for (InterfaceDecl key : tests.keySet()) {
        getImportsFrom(mn, qn, key.getModuleDecl());
        for (ClassDecl clazz : tests.get(key)) {
            getImportsFrom(mn, qn, clazz.getModuleDecl());
        }
    }
    for (String m : mn) {
        imports.add(new StarImport(m));
    }
    if (!qn.isEmpty()) {
        List<Name> names = new List<>();
        for (String q : qn) {
            names.add(new Name(q));
        }
        imports.add(new NamedImport(names));
    }
    return imports;
}
Also used : Import(org.abs_models.frontend.ast.Import) NamedImport(org.abs_models.frontend.ast.NamedImport) StarImport(org.abs_models.frontend.ast.StarImport) FromImport(org.abs_models.frontend.ast.FromImport) ClassDecl(org.abs_models.frontend.ast.ClassDecl) StarImport(org.abs_models.frontend.ast.StarImport) List(org.abs_models.frontend.ast.List) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) HashSet(java.util.HashSet) Name(org.abs_models.frontend.ast.Name) NamedImport(org.abs_models.frontend.ast.NamedImport)

Example 3 with InterfaceDecl

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

the class StringBasedABSTestRunnerGenerator method generateMainBlock.

private TestRunnerScriptBuilder generateMainBlock(TestRunnerScriptBuilder imports) {
    TestRunnerScriptBuilder builder = new TestRunnerScriptBuilder();
    builder.increaseIndent();
    Set<Type> paramNames = new HashSet<>();
    builder.append("Set<Fut<Unit>> ").append(futs).append(" = EmptySet;").newLine();
    builder.append("Fut<Unit> ").append(fut).append(";").newLine();
    for (InterfaceDecl key : tests.keySet()) {
        builder.append("//Test cases for ").append(key.getType().getQualifiedName()).newLine();
        for (ClassDecl clazz : tests.get(key)) {
            builder.append("//Test cases for implementation ").append(clazz.getName()).newLine();
            paramNames.addAll(generateTestClassImpl(key, clazz, builder));
        }
    }
    generateWaitSync(builder);
    generateImports(imports, paramNames);
    return builder;
}
Also used : Type(org.abs_models.frontend.typechecker.Type) ClassDecl(org.abs_models.frontend.ast.ClassDecl) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) HashSet(java.util.HashSet)

Example 4 with InterfaceDecl

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

the class ASTBasedABSTestRunnerGenerator method generateMainBlockAST.

private MainBlock generateMainBlockAST(List<Import> list) {
    final MainBlock block = new MainBlock();
    DataConstructorExp empty = new DataConstructorExp("EmptySet", new List<>());
    VarDeclStmt futsStatement = getVarDecl(futs, getType("Set", getFutUnitType()), empty);
    block.addStmtNoTransform(futsStatement);
    VarDeclStmt futStatement = getVarDecl(fut, getFutUnitType(), null);
    block.addStmtNoTransform(futStatement);
    Set<TypeUse> use = new HashSet<>();
    for (InterfaceDecl key : tests.keySet()) {
        for (ClassDecl clazz : tests.get(key)) {
            use.addAll(generateTestClassImplAST(key, clazz, block));
        }
    }
    block.addStmtNoTransform(generateWaitSyncAST());
    return block;
}
Also used : DataConstructorExp(org.abs_models.frontend.ast.DataConstructorExp) DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) TypeUse(org.abs_models.frontend.ast.TypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) ClassDecl(org.abs_models.frontend.ast.ClassDecl) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) MainBlock(org.abs_models.frontend.ast.MainBlock) HashSet(java.util.HashSet)

Example 5 with InterfaceDecl

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

the class TypeCheckerTest method methodSigs.

@Test
public void methodSigs() {
    Model m = assertParse("interface I { Unit m(); } interface J { Unit n(); } interface K extends I, J { Unit foo(); } { K k; } ");
    ModuleDecl module = m.lookupModule("UnitTest");
    InterfaceDecl d = (InterfaceDecl) module.getDecl(2);
    ArrayList<MethodSig> list = new ArrayList<>(d.getAllMethodSigs());
    assertEquals(list.toString(), 3, list.size());
    VarDeclStmt stmt = (VarDeclStmt) module.getBlock().getStmt(0);
    Collection<MethodSig> sigs = stmt.getVarDecl().getTypeUse().getType().getAllMethodSigs();
    assertArrayEquals(sigs.toArray(), d.getAllMethodSigs().toArray());
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Model(org.abs_models.frontend.ast.Model) ArrayList(java.util.ArrayList) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

InterfaceDecl (org.abs_models.frontend.ast.InterfaceDecl)7 HashSet (java.util.HashSet)4 FrontendTest (org.abs_models.frontend.FrontendTest)3 ClassDecl (org.abs_models.frontend.ast.ClassDecl)3 Model (org.abs_models.frontend.ast.Model)3 Test (org.junit.Test)3 MethodSig (org.abs_models.frontend.ast.MethodSig)2 VarDeclStmt (org.abs_models.frontend.ast.VarDeclStmt)2 ArrayList (java.util.ArrayList)1 ABSTest (org.abs_models.ABSTest)1 DataConstructorExp (org.abs_models.frontend.ast.DataConstructorExp)1 DataTypeUse (org.abs_models.frontend.ast.DataTypeUse)1 FromImport (org.abs_models.frontend.ast.FromImport)1 Import (org.abs_models.frontend.ast.Import)1 InterfaceTypeUse (org.abs_models.frontend.ast.InterfaceTypeUse)1 List (org.abs_models.frontend.ast.List)1 MainBlock (org.abs_models.frontend.ast.MainBlock)1 ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)1 Name (org.abs_models.frontend.ast.Name)1 NamedImport (org.abs_models.frontend.ast.NamedImport)1