Search in sources :

Example 1 with VarOrFieldDecl

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

the class VarResolutionTest method testNestedLetExp5.

@Test
public void testNestedLetExp5() {
    Model m = assertParse("def Bool f(Bool b) = let (Bool x) = b in let (Bool x) = x in x;");
    LetExp e = (LetExp) getFirstFunctionExpr(m);
    LetExp e2 = (LetExp) e.getExp();
    VarOrFieldDecl decl = e.getVar();
    VarUse u = (VarUse) e2.getVal();
    assertEquals(decl, u.getDecl());
}
Also used : VarOrFieldDecl(org.abs_models.frontend.ast.VarOrFieldDecl) LetExp(org.abs_models.frontend.ast.LetExp) Model(org.abs_models.frontend.ast.Model) VarUse(org.abs_models.frontend.ast.VarUse) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 2 with VarOrFieldDecl

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

the class VarResolutionTest method testNestedLetExp2.

@Test
public void testNestedLetExp2() {
    Model m = assertParse(" def Bool f(Bool b) = let (Bool x) = let (Bool x) = b in x in x;");
    LetExp e = (LetExp) getFirstFunctionExpr(m);
    VarOrFieldDecl decl = e.getVar();
    VarUse u = (VarUse) e.getExp();
    assertEquals(decl, u.getDecl());
}
Also used : VarOrFieldDecl(org.abs_models.frontend.ast.VarOrFieldDecl) LetExp(org.abs_models.frontend.ast.LetExp) Model(org.abs_models.frontend.ast.Model) VarUse(org.abs_models.frontend.ast.VarUse) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 3 with VarOrFieldDecl

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

the class VarResolutionTest method testNestedLetExp3.

@Test
public void testNestedLetExp3() {
    Model m = assertParse(" def Bool f(Bool b) = let (Bool x) = b in let (Bool y) = b in x;");
    LetExp e = (LetExp) getFirstFunctionExpr(m);
    LetExp e2 = (LetExp) e.getExp();
    VarOrFieldDecl decl = e.getVar();
    VarUse u = (VarUse) e2.getExp();
    assertEquals(decl, u.getDecl());
}
Also used : VarOrFieldDecl(org.abs_models.frontend.ast.VarOrFieldDecl) LetExp(org.abs_models.frontend.ast.LetExp) Model(org.abs_models.frontend.ast.Model) VarUse(org.abs_models.frontend.ast.VarUse) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 4 with VarOrFieldDecl

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

Example 5 with VarOrFieldDecl

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

the class JavaGeneratorHelper method isLocalVarUse.

/**
 * checks if astNode is a use of a local variable or parameter
 */
private static boolean isLocalVarUse(ASTNode<?> astNode) {
    if (astNode instanceof VarUse) {
        VarUse v = (VarUse) astNode;
        VarOrFieldDecl decl = v.getDecl();
        if (decl instanceof VarDecl || decl instanceof ParamDecl) {
            return !(decl.getParent() instanceof LetExp);
        }
    }
    return false;
}
Also used : TypedVarOrFieldDecl(org.abs_models.frontend.ast.TypedVarOrFieldDecl) VarOrFieldDecl(org.abs_models.frontend.ast.VarOrFieldDecl) VarDecl(org.abs_models.frontend.ast.VarDecl) ParamDecl(org.abs_models.frontend.ast.ParamDecl) LetExp(org.abs_models.frontend.ast.LetExp) VarUse(org.abs_models.frontend.ast.VarUse)

Aggregations

VarOrFieldDecl (org.abs_models.frontend.ast.VarOrFieldDecl)8 LetExp (org.abs_models.frontend.ast.LetExp)7 VarUse (org.abs_models.frontend.ast.VarUse)7 FrontendTest (org.abs_models.frontend.FrontendTest)6 Model (org.abs_models.frontend.ast.Model)6 Test (org.junit.Test)6 TypedVarOrFieldDecl (org.abs_models.frontend.ast.TypedVarOrFieldDecl)2 TypeError (org.abs_models.frontend.analyser.TypeError)1 FieldDecl (org.abs_models.frontend.ast.FieldDecl)1 ParamDecl (org.abs_models.frontend.ast.ParamDecl)1 VarDecl (org.abs_models.frontend.ast.VarDecl)1