Search in sources :

Example 1 with ParametricDataTypeUse

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

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

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

Example 4 with ParametricDataTypeUse

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

the class AbsASTBuilderUtil method getType.

public static final DataTypeUse getType(String n, TypeUse... types) {
    if (types.length > 0) {
        ParametricDataTypeUse set = new ParametricDataTypeUse();
        set.setName(n);
        for (TypeUse d : types) {
            set.addParam(d);
        }
        return set;
    } else {
        DataTypeUse set = new DataTypeUse();
        set.setName(n);
        return set;
    }
}
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) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse)

Example 5 with ParametricDataTypeUse

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

the class AbsASTBuilderUtil method generateImportAST.

public static final Set<Import> generateImportAST(TypeUse t) {
    Set<Import> imports = new HashSet<>();
    imports.add(generateImportAST(t.getName(), t.getModuleDecl().getName()));
    if (t instanceof ParametricDataTypeUse) {
        for (TypeUse st : ((ParametricDataTypeUse) t).getParams()) {
            imports.addAll(generateImportAST(st));
        }
    }
    return imports;
}
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) Import(org.abs_models.frontend.ast.Import) FromImport(org.abs_models.frontend.ast.FromImport) HashSet(java.util.HashSet) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse)

Aggregations

DataTypeUse (org.abs_models.frontend.ast.DataTypeUse)5 ParametricDataTypeUse (org.abs_models.frontend.ast.ParametricDataTypeUse)5 TypeUse (org.abs_models.frontend.ast.TypeUse)5 InterfaceTypeUse (org.abs_models.frontend.ast.InterfaceTypeUse)4 ABSTest (org.abs_models.ABSTest)2 FrontendTest (org.abs_models.frontend.FrontendTest)2 Block (org.abs_models.frontend.ast.Block)2 Model (org.abs_models.frontend.ast.Model)2 VarDeclStmt (org.abs_models.frontend.ast.VarDeclStmt)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 FromImport (org.abs_models.frontend.ast.FromImport)1 Import (org.abs_models.frontend.ast.Import)1 InterfaceDecl (org.abs_models.frontend.ast.InterfaceDecl)1 MethodSig (org.abs_models.frontend.ast.MethodSig)1 SyncCall (org.abs_models.frontend.ast.SyncCall)1 TypeIdUse (org.abs_models.frontend.ast.TypeIdUse)1 VarUse (org.abs_models.frontend.ast.VarUse)1 InterfaceType (org.abs_models.frontend.typechecker.InterfaceType)1