Search in sources :

Example 1 with VarDeclStmt

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

the class TypeCheckerTest method ticket414_futNeedsDataType1.

@Test
public void ticket414_futNeedsDataType1() {
    Model m = assertParse("module M; interface I {} { Fut<I> fi; }");
    assertFalse(m.hasErrors());
    Block b = m.getMainBlock();
    assertNotNull(b);
    VarDeclStmt s = (VarDeclStmt) b.getStmt(0);
    ParametricDataTypeUse u = (ParametricDataTypeUse) s.getVarDecl().getTypeUse();
    // Have:
    TypeUse tu = u.getParam(0);
    assertEquals("I", tu.getName());
    assertThat(tu, instanceOf(InterfaceTypeUse.class));
    assertThat(tu.getType(), instanceOf(InterfaceType.class));
    assertThat(tu.getDecl(), instanceOf(InterfaceDecl.class));
}
Also used : DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) TypeUse(org.abs_models.frontend.ast.TypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) InterfaceTypeUse(org.abs_models.frontend.ast.InterfaceTypeUse) InterfaceType(org.abs_models.frontend.typechecker.InterfaceType) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Model(org.abs_models.frontend.ast.Model) InterfaceTypeUse(org.abs_models.frontend.ast.InterfaceTypeUse) Block(org.abs_models.frontend.ast.Block) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 2 with VarDeclStmt

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

the class TypeCheckerTest method ticket414_futNeedsDataType2.

@Test
public void ticket414_futNeedsDataType2() {
    Model m = assertParse("module M; data I = I; { Fut<I> fi; }");
    assertFalse(m.hasErrors());
    Block b = m.getMainBlock();
    assertNotNull(b);
    VarDeclStmt s = (VarDeclStmt) b.getStmt(0);
    ParametricDataTypeUse u = (ParametricDataTypeUse) s.getVarDecl().getTypeUse();
    // Have:
    TypeUse tu = u.getParam(0);
    assertEquals("I", tu.getName());
    assertThat(tu, instanceOf(DataTypeUse.class));
}
Also used : DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) TypeUse(org.abs_models.frontend.ast.TypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) InterfaceTypeUse(org.abs_models.frontend.ast.InterfaceTypeUse) DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Model(org.abs_models.frontend.ast.Model) Block(org.abs_models.frontend.ast.Block) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 3 with VarDeclStmt

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

the class AnnotationTests method testVarDecl.

@Test
public void testVarDecl() {
    Model m = assertParseOkAnn("{ [Near] I i; }");
    VarDeclStmt v = ((VarDeclStmt) m.getMainBlock().getStmt(0));
    assertHasLocAnnotation(v.getVarDecl().getType(), "Near");
}
Also used : VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Model(org.abs_models.frontend.ast.Model) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 4 with VarDeclStmt

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

the class FrontendTest method getTypeOfNthAssignment.

protected Type getTypeOfNthAssignment(Model m, int n) {
    int count = 0;
    for (Stmt s : m.getMainBlock().getStmts()) {
        Type t = null;
        if (s instanceof AssignStmt) {
            AssignStmt as = (AssignStmt) s;
            t = as.getValue().getType();
        } else if (s instanceof VarDeclStmt) {
            VarDeclStmt vd = (VarDeclStmt) s;
            if (vd.getVarDecl().hasInitExp()) {
                t = vd.getVarDecl().getInitExp().getType();
            }
        }
        if (t != null) {
            count++;
            if (count == n) {
                return t;
            }
        }
    }
    return null;
}
Also used : Type(org.abs_models.frontend.typechecker.Type) AssignStmt(org.abs_models.frontend.ast.AssignStmt) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Stmt(org.abs_models.frontend.ast.Stmt) AssignStmt(org.abs_models.frontend.ast.AssignStmt) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) ExpressionStmt(org.abs_models.frontend.ast.ExpressionStmt)

Example 5 with VarDeclStmt

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

Aggregations

VarDeclStmt (org.abs_models.frontend.ast.VarDeclStmt)8 Model (org.abs_models.frontend.ast.Model)6 FrontendTest (org.abs_models.frontend.FrontendTest)5 Test (org.junit.Test)5 ABSTest (org.abs_models.ABSTest)3 DataTypeUse (org.abs_models.frontend.ast.DataTypeUse)3 InterfaceDecl (org.abs_models.frontend.ast.InterfaceDecl)3 ParametricDataTypeUse (org.abs_models.frontend.ast.ParametricDataTypeUse)3 TypeUse (org.abs_models.frontend.ast.TypeUse)3 Block (org.abs_models.frontend.ast.Block)2 ClassDecl (org.abs_models.frontend.ast.ClassDecl)2 InterfaceTypeUse (org.abs_models.frontend.ast.InterfaceTypeUse)2 Stmt (org.abs_models.frontend.ast.Stmt)2 Type (org.abs_models.frontend.typechecker.Type)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)1 AssignStmt (org.abs_models.frontend.ast.AssignStmt)1 DataConstructorExp (org.abs_models.frontend.ast.DataConstructorExp)1 ExpressionStmt (org.abs_models.frontend.ast.ExpressionStmt)1