Search in sources :

Example 1 with VarDeclStmt

use of abs.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(abs.frontend.typechecker.Type) AssignStmt(abs.frontend.ast.AssignStmt) VarDeclStmt(abs.frontend.ast.VarDeclStmt) VarDeclStmt(abs.frontend.ast.VarDeclStmt) AssignStmt(abs.frontend.ast.AssignStmt) Stmt(abs.frontend.ast.Stmt) ExpressionStmt(abs.frontend.ast.ExpressionStmt)

Example 2 with VarDeclStmt

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

the class OtherAnalysisTests method awaitRewriteModule1.

@Test
public void awaitRewriteModule1() {
    Model.doAACrewrite = false;
    Model m = assertParseOk("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}");
    ClassDecl c = (ClassDecl) m.lookupModule("C").getDecl(0);
    ReturnStmt ret = (ReturnStmt) c.getMethod(0).getBlock().getStmt(0);
    assertThat(ret.getRetExp().getType(), instanceOf(DataTypeType.class));
    assertEquals("A.X", ret.getRetExp().getType().getQualifiedName());
    Model.doAACrewrite = true;
    m = assertParseOk("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}", Config.WITH_STD_LIB);
    c = (ClassDecl) m.lookupModule("C").getDecl(0);
    Stmt s = c.getMethod(0).getBlock().getStmt(0);
    VarDeclStmt b = (VarDeclStmt) s;
    Type t = ((DataTypeType) b.getVarDecl().getType()).getTypeArg(0);
    assertEquals("A.X", t.getQualifiedName());
}
Also used : Type(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType) ClassDecl(abs.frontend.ast.ClassDecl) VarDeclStmt(abs.frontend.ast.VarDeclStmt) Model(abs.frontend.ast.Model) DataTypeType(abs.frontend.typechecker.DataTypeType) ReturnStmt(abs.frontend.ast.ReturnStmt) Stmt(abs.frontend.ast.Stmt) VarDeclStmt(abs.frontend.ast.VarDeclStmt) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 3 with VarDeclStmt

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

the class LocationTypeTests method assertInfer.

private Model assertInfer(String code, LocationType expected, boolean fails) {
    Model m = assertParse(code, WITH_STD_LIB);
    // m.setLocationTypingEnabled(true);
    LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(m);
    m.registerTypeSystemExtension(ltie);
    SemanticConditionList e = m.typeCheck();
    // System.out.println(ltie.getConstraints());
    assertEquals(!e.containsErrors() ? "" : "Found error: " + e.getFirstError().getMessage(), fails, e.containsErrors());
    // assertEquals(fails, generated == null);
    if (expected != null) {
        VarDeclStmt vds = ((VarDeclStmt) m.getMainBlock().getStmt(0));
        LocationType t = ltie.getResults().get(LocationTypeInferrerExtension.getLV(vds.getVarDecl().getType()));
        assertTrue(t.toString(), expected == LocationType.FAR ? t == LocationType.FAR || t.isParametricFar() : expected == t);
    }
    return m;
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) VarDeclStmt(abs.frontend.ast.VarDeclStmt) Model(abs.frontend.ast.Model) LocationType(abs.frontend.typechecker.locationtypes.LocationType)

Example 4 with VarDeclStmt

use of abs.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(abs.frontend.ast.VarDeclStmt) Model(abs.frontend.ast.Model) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 5 with VarDeclStmt

use of abs.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(abs.frontend.ast.DataConstructorExp) TypeUse(abs.frontend.ast.TypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) ClassDecl(abs.frontend.ast.ClassDecl) VarDeclStmt(abs.frontend.ast.VarDeclStmt) InterfaceDecl(abs.frontend.ast.InterfaceDecl) MainBlock(abs.frontend.ast.MainBlock) HashSet(java.util.HashSet)

Aggregations

VarDeclStmt (abs.frontend.ast.VarDeclStmt)5 Model (abs.frontend.ast.Model)3 FrontendTest (abs.frontend.FrontendTest)2 ClassDecl (abs.frontend.ast.ClassDecl)2 Stmt (abs.frontend.ast.Stmt)2 Type (abs.frontend.typechecker.Type)2 Test (org.junit.Test)2 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)1 AssignStmt (abs.frontend.ast.AssignStmt)1 DataConstructorExp (abs.frontend.ast.DataConstructorExp)1 DataTypeUse (abs.frontend.ast.DataTypeUse)1 ExpressionStmt (abs.frontend.ast.ExpressionStmt)1 InterfaceDecl (abs.frontend.ast.InterfaceDecl)1 MainBlock (abs.frontend.ast.MainBlock)1 ParametricDataTypeUse (abs.frontend.ast.ParametricDataTypeUse)1 ReturnStmt (abs.frontend.ast.ReturnStmt)1 TypeUse (abs.frontend.ast.TypeUse)1 DataTypeType (abs.frontend.typechecker.DataTypeType)1 LocationType (abs.frontend.typechecker.locationtypes.LocationType)1 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)1