Search in sources :

Example 11 with FieldDecl

use of abs.frontend.ast.FieldDecl in project abstools by abstools.

the class ClassDeclGenerator method generateFields.

private void generateFields() {
    for (ParamDecl p : decl.getParams()) {
        stream.print("private ");
        p.generateJava(stream);
        stream.println(";");
    }
    for (FieldDecl f : decl.getFields()) {
        f.generateJava(stream);
    }
}
Also used : FieldDecl(abs.frontend.ast.FieldDecl) ParamDecl(abs.frontend.ast.ParamDecl)

Example 12 with FieldDecl

use of abs.frontend.ast.FieldDecl in project abstools by abstools.

the class InferMain method shouldBeConsidered.

private boolean shouldBeConsidered(LocationTypeVariable ltv) {
    ASTNode<?> node = ltv.getNode();
    Decl contextDecl = node.getContextDecl();
    if (contextDecl != null) {
        // Don't print interface annotations in "implements/extends" clauses:
        if (node instanceof InterfaceTypeUse && (contextDecl instanceof ClassDecl || contextDecl instanceof InterfaceDecl))
            return false;
        if (contextDecl.isClass() && !config.contains(Config.CLASSES))
            return false;
        if (contextDecl.isInterface() && !config.contains(Config.INTERFACES))
            return false;
        if (contextDecl.isFunction() && !config.contains(Config.FUNCTIONS))
            return false;
    }
    if (node instanceof VarDecl && !config.contains(Config.LOCAL_VAR_DECLS))
        return false;
    if (node instanceof FieldDecl && !config.contains(Config.FIELDS))
        return false;
    if (ltv.getAnnotatedType() != null) {
        return false;
    }
    return true;
}
Also used : FieldDecl(abs.frontend.ast.FieldDecl) ClassDecl(abs.frontend.ast.ClassDecl) VarDecl(abs.frontend.ast.VarDecl) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) InterfaceDecl(abs.frontend.ast.InterfaceDecl) ClassDecl(abs.frontend.ast.ClassDecl) FieldDecl(abs.frontend.ast.FieldDecl) VarDecl(abs.frontend.ast.VarDecl) Decl(abs.frontend.ast.Decl) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Example 13 with FieldDecl

use of abs.frontend.ast.FieldDecl 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 : VarOrFieldDecl(abs.frontend.ast.VarOrFieldDecl) FieldDecl(abs.frontend.ast.FieldDecl) TypedVarOrFieldDecl(abs.frontend.ast.TypedVarOrFieldDecl) VarOrFieldDecl(abs.frontend.ast.VarOrFieldDecl) TypedVarOrFieldDecl(abs.frontend.ast.TypedVarOrFieldDecl) TypedVarOrFieldDecl(abs.frontend.ast.TypedVarOrFieldDecl) TypeError(abs.frontend.analyser.TypeError)

Example 14 with FieldDecl

use of abs.frontend.ast.FieldDecl in project abstools by abstools.

the class ABSUnitTestCaseBuilder method createObjectsInHeap.

void createObjectsInHeap(String testMethodName, Set<String> heapNames, Map<String, InterfaceTypeUse> objectsInHeap, ClassDecl testClass, Map<ABSRef, ABSObject> initialHeap, Block testMethodBlock) {
    String setMethodForTest = testCaseNameBuilder.initialTestMethodName(testMethodName);
    Block modifyBlock = initialiseDeltaForTestClass(testClass, testCaseNameBuilder.initialTestMethodName(testMethodName));
    testMethodBlock.addStmtNoTransform(getExpStmt(getCall(getThis(), setMethodForTest, true)));
    Map<String, String> typeHierarchy = new HashMap<String, String>();
    Map<String, List<Stmt>> initialisations = new HashMap<String, List<Stmt>>();
    List<String> initialisationsOrders = new ArrayList<String>();
    for (ABSRef r : initialHeap.keySet()) {
        makeSetStatements(typeHierarchy, initialisations, initialisationsOrders, testMethodName, heapNames, initialHeap, objectsInHeap, r, initialHeap.get(r), testClass);
    }
    for (String ref : initialisationsOrders) {
        for (Stmt s : initialisations.get(ref)) {
            modifyBlock.addStmtNoTransform(s);
        }
    }
    String testClassName = testClass.getName();
    DeltaDecl delta = deltaBuilder.getDeltaFor(testClassName);
    ModifyClassModifier cm = null;
    for (ModuleModifier m : delta.getModuleModifiers()) {
        if (m.getName().equals(testClassName)) {
            cm = (ModifyClassModifier) m;
            break;
        }
    }
    for (String r : objectsInHeap.keySet()) {
        FieldDecl field = new FieldDecl();
        field.setName(r);
        InterfaceTypeUse inf = objectsInHeap.get(r);
        field.setAccess(inf);
        testClass.addField(field);
        // allow access of subtype information
        cm.addModifier(new RemoveFieldModifier(field.treeCopyNoTransform()));
        FieldDecl newField = new FieldDecl();
        newField.setName(r);
        newField.setAccess(new InterfaceTypeUse(typeHierarchy.get(inf.getName()), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
        cm.addModifier(new AddFieldModifier(newField));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RemoveFieldModifier(abs.frontend.ast.RemoveFieldModifier) DeltaDecl(abs.frontend.ast.DeltaDecl) AbsASTBuilderUtil.getExpStmt(abs.backend.tests.AbsASTBuilderUtil.getExpStmt) Stmt(abs.frontend.ast.Stmt) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) FieldDecl(abs.frontend.ast.FieldDecl) ABSRef(apet.testCases.ABSRef) ModuleModifier(abs.frontend.ast.ModuleModifier) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) Block(abs.frontend.ast.Block) List(java.util.List) ArrayList(java.util.ArrayList) AddFieldModifier(abs.frontend.ast.AddFieldModifier)

Aggregations

FieldDecl (abs.frontend.ast.FieldDecl)14 ParamDecl (abs.frontend.ast.ParamDecl)6 ClassDecl (abs.frontend.ast.ClassDecl)4 InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)4 MethodImpl (abs.frontend.ast.MethodImpl)3 TypeError (abs.frontend.analyser.TypeError)2 DeltaDecl (abs.frontend.ast.DeltaDecl)2 InterfaceDecl (abs.frontend.ast.InterfaceDecl)2 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)2 VarUse (abs.frontend.ast.VarUse)2 ABSDynamicClass (abs.backend.java.lib.runtime.ABSDynamicClass)1 ABSField (abs.backend.java.lib.runtime.ABSField)1 ABSValue (abs.backend.java.lib.types.ABSValue)1 AbsASTBuilderUtil.createMethodImpl (abs.backend.tests.AbsASTBuilderUtil.createMethodImpl)1 AbsASTBuilderUtil.createMethodSig (abs.backend.tests.AbsASTBuilderUtil.createMethodSig)1 AbsASTBuilderUtil.getExpStmt (abs.backend.tests.AbsASTBuilderUtil.getExpStmt)1 FrontendTest (abs.frontend.FrontendTest)1 AddFieldModifier (abs.frontend.ast.AddFieldModifier)1 AddInterfaceModifier (abs.frontend.ast.AddInterfaceModifier)1 AddMethodModifier (abs.frontend.ast.AddMethodModifier)1