Search in sources :

Example 1 with TypedVarOrFieldDecl

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

the class ClassGenerator method generateDataAccess.

private void generateDataAccess() {
    ecs.println("%% --- Internal state and low-level accessors\n");
    ecs.format("-record(state,{'class'=%s", modName);
    for (TypedVarOrFieldDecl f : Iterables.concat(classDecl.getParams(), classDecl.getFields())) {
        ecs.print(",");
        ecs.format("'%s'=null", f.getName());
    }
    ecs.println("}).");
    ErlUtil.functionHeader(ecs, "init_internal");
    ecs.println("#state{}.");
    ecs.decIndent();
    ecs.println();
    for (TypedVarOrFieldDecl f : Iterables.concat(classDecl.getParams(), classDecl.getFields())) {
        ecs.pf(" %%%% %s:%s", f.getFileName(), f.getStartLine());
        ErlUtil.functionHeader(ecs, "get_val_internal", Mask.none, String.format("#state{'%s'=G}", f.getName()), "'" + f.getName() + "'");
        ecs.println("object:register_read('" + f.getName() + "'),");
        ecs.println("G;");
        ecs.decIndent();
    }
    ErlUtil.functionHeader(ecs, "get_val_internal", Mask.none, "_", "_");
    ecs.println("%% Invalid return value; handled by HTTP API when querying for non-existant field.");
    ecs.println("%% Will never occur in generated code.");
    ecs.println("none.");
    ecs.decIndent();
    ecs.println();
    if (hasFields) {
        boolean first = true;
        for (TypedVarOrFieldDecl f : Iterables.concat(classDecl.getParams(), classDecl.getFields())) {
            if (!first) {
                ecs.println(";");
                ecs.decIndent();
            }
            first = false;
            ecs.pf(" %%%% %s:%s", f.getFileName(), f.getStartLine());
            ErlUtil.functionHeader(ecs, "set_val_internal", Mask.none, "S", "'" + f.getName() + "'", "V");
            ecs.println("object:register_write('" + f.getName() + "'),");
            ecs.format("S#state{'%s'=V}", f.getName());
        }
        ecs.println(".");
        ecs.decIndent();
        ecs.println();
    } else {
        // Generate failing Dummy
        ErlUtil.functionHeader(ecs, "set_val_internal", Mask.none, "S", "S", "S");
        ecs.println("throw(badarg).");
        ecs.decIndent();
    }
    ErlUtil.functionHeader(ecs, "get_state_for_modelapi", Mask.none, "S");
    ecs.println("[");
    ecs.incIndent();
    boolean first = true;
    for (TypedVarOrFieldDecl f : Iterables.concat(classDecl.getParams(), classDecl.getFields())) {
        if (!first)
            ecs.print(", ");
        first = false;
        ecs.pf("{ '%s', S#state.'%s' }", f.getName(), f.getName());
    }
    ecs.decIndent();
    ecs.println("].");
    ecs.decIndent();
}
Also used : TypedVarOrFieldDecl(org.abs_models.frontend.ast.TypedVarOrFieldDecl)

Example 2 with TypedVarOrFieldDecl

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

the class FinalAnnotationTypeExtension method checkAssignStmt.

@Override
public void checkAssignStmt(AssignStmt s) {
    VarOrFieldDecl decl = s.getVar().getDecl();
    if (decl instanceof TypedVarOrFieldDecl) {
        TypedVarOrFieldDecl d = (TypedVarOrFieldDecl) decl;
        // Not sure if this code will encounter delta bodies:
        if (d.isFinal()) {
            String name = d.getName();
            boolean isField = (d instanceof FieldDecl);
            String kind = isField ? "field" : "variable";
            add(new TypeError(s, ErrorMessage.ASSIGN_TO_FINAL, kind, name));
        }
    } else {
    // It's a PatternVarDecl.  Assume these are never final.
    }
}
Also used : TypedVarOrFieldDecl(org.abs_models.frontend.ast.TypedVarOrFieldDecl) FieldDecl(org.abs_models.frontend.ast.FieldDecl) VarOrFieldDecl(org.abs_models.frontend.ast.VarOrFieldDecl) TypedVarOrFieldDecl(org.abs_models.frontend.ast.TypedVarOrFieldDecl) VarOrFieldDecl(org.abs_models.frontend.ast.VarOrFieldDecl) TypedVarOrFieldDecl(org.abs_models.frontend.ast.TypedVarOrFieldDecl) TypeError(org.abs_models.frontend.analyser.TypeError)

Aggregations

TypedVarOrFieldDecl (org.abs_models.frontend.ast.TypedVarOrFieldDecl)2 TypeError (org.abs_models.frontend.analyser.TypeError)1 FieldDecl (org.abs_models.frontend.ast.FieldDecl)1 VarOrFieldDecl (org.abs_models.frontend.ast.VarOrFieldDecl)1