Search in sources :

Example 1 with MethodSig

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

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

the class JavaGeneratorHelper method generateAwaitAsyncCall.

public static void generateAwaitAsyncCall(PrintStream stream, AwaitAsyncCall call) {
    final PureExp callee = call.getCallee();
    final List<PureExp> params = call.getParams();
    final MethodSig sig = call.getMethodSig();
    final List<Annotation> annotations = call.getAnnotations();
    // FIXME: implement await, assignment afterwards
    // OutputStream exprOStream = new ByteArrayOutputStream();
    // PrintStream exprStream = new PrintStream(exprOStream);
    // ClaimGuard guard = new ClaimGuard();
    // // Necessary temporary variables are written to "stream" and the
    // // await-expression is written to exprStream
    // 
    // // FIXME: implement await, assignment afterwards
    // guard.generateJavaGuard(stream, exprStream);
    // stream.print(JavaBackendConstants.ABSRUNTIME + ".await(");
    // stream.print(exprOStream.toString());
    // stream.println(");");
    generateAsyncCall(stream, null, callee, callee.getType(), params, null, sig, annotations);
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) PureExp(org.abs_models.frontend.ast.PureExp) Annotation(org.abs_models.frontend.ast.Annotation)

Example 3 with MethodSig

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

the class JavaGeneratorHelper method generateAsyncMethod.

public static void generateAsyncMethod(PrintStream stream, MethodImpl method) {
    final MethodSig sig = method.getMethodSig();
    generateMethodSig(stream, sig, true, "final", "");
    stream.println(" {");
    stream.print("return (" + ABSFut.class.getName() + ")");
    generateAsyncCall(stream, "this", null, method.getContextDecl().getType(), null, sig.getParams(), sig, new List<>());
    stream.println(";");
    stream.println("}");
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig)

Example 4 with MethodSig

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

the class TraitTest method addAddModifierAtRuntimeBackComp.

@Test
public void addAddModifierAtRuntimeBackComp() {
    Model model = assertParse("module M;" + "class C { Unit m(){skip;} }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    MethodSig sig = AbsASTBuilderUtil.createMethodSig("n", AbsASTBuilderUtil.getUnit());
    MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt())));
    AddMethodModifier opr = new AddMethodModifier(impl);
    assertNotNull(opr.getMethodImpl());
    ModifyClassModifier mcn = new ModifyClassModifier();
    mcn.setName("M.C");
    DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
    DeltaDecl dd = new DeltaDecl();
    dd.setName("MyDelta");
    dd.setImportedModule(acc);
    dd.addModuleModifier(mcn);
    mcn.addModifier(opr);
    mcn.setParent(dd);
    acc.setParent(dd);
    opr.setParent(mcn);
    sig.setParent(opr);
    CompilationUnit cu = model.getCompilationUnitList().getChild(0);
    cu.addDeltaDecl(dd);
    dd.setParent(cu);
    model.applyDelta(dd);
    assertEquals(2, cls.getMethods().getNumChild());
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) MethodSig(org.abs_models.frontend.ast.MethodSig) ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) DeltaAccess(org.abs_models.frontend.ast.DeltaAccess) AddMethodModifier(org.abs_models.frontend.ast.AddMethodModifier) Model(org.abs_models.frontend.ast.Model) Block(org.abs_models.frontend.ast.Block) List(org.abs_models.frontend.ast.List) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) SkipStmt(org.abs_models.frontend.ast.SkipStmt) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 5 with MethodSig

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

the class ASTBasedABSTestRunnerGenerator method generateDataPointsAST.

private TypeUse generateDataPointsAST(InterfaceDecl key, ClassDecl clazz, Set<TypeUse> use, MainBlock block) {
    MethodSig dataPoint = findDataPoints(key);
    if (dataPoint == null) {
        return null;
    }
    TypeIdUse rt = dataPoint.getReturnType();
    if (!(rt instanceof ParametricDataTypeUse)) {
        return null;
    }
    ParametricDataTypeUse prt = (ParametricDataTypeUse) rt;
    if (!prt.getName().equals("Set")) {
        return null;
    }
    // Set has only one type parameter
    TypeUse u = (TypeUse) prt.getParam(0).copy();
    use.add(u);
    String objName = uncap(clazz.getName()) + "dataPoint";
    String dataSet = dataPointSetName(clazz);
    block.addStmtNoTransform(newObj(key, clazz, objName, true));
    block.addStmtNoTransform(getVarDecl(dataSet, prt.copy(), new SyncCall(new VarUse(objName), dataPoint.getName(), new List<>())));
    return u;
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) TypeUse(org.abs_models.frontend.ast.TypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) SyncCall(org.abs_models.frontend.ast.SyncCall) TypeIdUse(org.abs_models.frontend.ast.TypeIdUse) VarUse(org.abs_models.frontend.ast.VarUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse)

Aggregations

MethodSig (org.abs_models.frontend.ast.MethodSig)14 List (org.abs_models.frontend.ast.List)4 Model (org.abs_models.frontend.ast.Model)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 Block (org.abs_models.frontend.ast.Block)3 ClassDecl (org.abs_models.frontend.ast.ClassDecl)3 CompilationUnit (org.abs_models.frontend.ast.CompilationUnit)3 DeltaAccess (org.abs_models.frontend.ast.DeltaAccess)3 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)3 MethodImpl (org.abs_models.frontend.ast.MethodImpl)3 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)3 ParamDecl (org.abs_models.frontend.ast.ParamDecl)3 Annotation (org.abs_models.frontend.ast.Annotation)2 DataTypeUse (org.abs_models.frontend.ast.DataTypeUse)2 InterfaceDecl (org.abs_models.frontend.ast.InterfaceDecl)2 ParametricDataTypeUse (org.abs_models.frontend.ast.ParametricDataTypeUse)2 PureExp (org.abs_models.frontend.ast.PureExp)2 SkipStmt (org.abs_models.frontend.ast.SkipStmt)2 TypeUse (org.abs_models.frontend.ast.TypeUse)2