Search in sources :

Example 1 with Block

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

the class ASTBasedABSTestRunnerGenerator method generateWaitSyncAST.

private WhileStmt generateWaitSyncAST() {
    WhileStmt ws = new WhileStmt();
    ws.setCondition(getFnApp("hasNext", new VarUse(futs)));
    Block body = new Block();
    DataTypeUse u = getType("Pair", getType("Set", getType("Fut", getType("Unit"))), getType("Fut", getType("Unit")));
    body.addStmtNoTransform(getVarDecl("nt", u, getFnApp("next", new VarUse(futs))));
    body.addStmtNoTransform(getVAssign(fut, getFnApp("snd", new VarUse("nt"))));
    body.addStmtNoTransform(getVAssign(futs, getFnApp("fst", new VarUse("nt"))));
    body.addStmtNoTransform(getExpStmt(new GetExp(new VarUse("fut"))));
    // Attach body at the end, since JastAdd will avoid touching ASTs without parents.
    ws.setBody(body);
    return ws;
}
Also used : WhileStmt(abs.frontend.ast.WhileStmt) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) Block(abs.frontend.ast.Block) MainBlock(abs.frontend.ast.MainBlock) GetExp(abs.frontend.ast.GetExp) VarUse(abs.frontend.ast.VarUse)

Example 2 with Block

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

the class TraitTest method addAddModifierAtRuntimeBackComp.

@Test
public void addAddModifierAtRuntimeBackComp() {
    Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    MethodSig sig = AbsASTBuilderUtil.createMethodSig("n", AbsASTBuilderUtil.getUnit());
    MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt())), false);
    AddMethodModifier opr = new AddMethodModifier(impl);
    assertNotNull(opr.getMethodImpl());
    ModifyClassModifier mcn = new ModifyClassModifier();
    mcn.setName("M.C");
    DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
    DeltaDecl dd = new DeltaDecl();
    dd.setName("MyDelta");
    dd.addDeltaAccess(acc);
    dd.addModuleModifier(mcn);
    mcn.addModifier(opr);
    mcn.setParent(dd);
    acc.setParent(dd);
    opr.setParent(mcn);
    sig.setParent(opr);
    CompilationUnit cu = model.getCompilationUnitList().getChild(0);
    cu.addDeltaDecl(dd);
    dd.setParent(cu);
    model.applyDelta(dd);
    assertEquals(2, cls.getMethods().getNumChild());
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) MethodSig(abs.frontend.ast.MethodSig) ClassDecl(abs.frontend.ast.ClassDecl) MethodImpl(abs.frontend.ast.MethodImpl) DeltaAccess(abs.frontend.ast.DeltaAccess) AddMethodModifier(abs.frontend.ast.AddMethodModifier) Model(abs.frontend.ast.Model) Block(abs.frontend.ast.Block) List(abs.frontend.ast.List) DeltaDecl(abs.frontend.ast.DeltaDecl) SkipStmt(abs.frontend.ast.SkipStmt) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 3 with Block

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

the class DeltaForGetSetFieldsBuilder method addSetter.

/**
 * Add an add method modifier
 * @param fieldName
 * @param exp
 * @param decl
 * @return
 */
AddMethodModifier addSetter(String fieldName, Access type) {
    MethodSig sig = new MethodSig(testCaseNameBuilder.setterMethodName(fieldName), new abs.frontend.ast.List<Annotation>(), getUnit(), new abs.frontend.ast.List<ParamDecl>());
    sig.addParam(new ParamDecl("v", type, new abs.frontend.ast.List<Annotation>()));
    Block block = new Block();
    block.addStmtNoTransform(getVAssign(new FieldUse(fieldName), new VarUse("v")));
    MethodImpl method = new MethodImpl(sig, block, false);
    AddMethodModifier modifier = new AddMethodModifier(method);
    return modifier;
}
Also used : AddMethodModifier(abs.frontend.ast.AddMethodModifier) VarUse(abs.frontend.ast.VarUse) Annotation(abs.frontend.ast.Annotation) AbsASTBuilderUtil.createMethodSig(abs.backend.tests.AbsASTBuilderUtil.createMethodSig) MethodSig(abs.frontend.ast.MethodSig) MethodImpl(abs.frontend.ast.MethodImpl) ParamDecl(abs.frontend.ast.ParamDecl) FieldUse(abs.frontend.ast.FieldUse) Block(abs.frontend.ast.Block)

Example 4 with Block

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

the class TraitTest method addModifyModifierAtRuntimeBackComp.

@Test
public void addModifyModifierAtRuntimeBackComp() {
    Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    MethodSig sig = AbsASTBuilderUtil.createMethodSig("m", AbsASTBuilderUtil.getUnit());
    MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt(), new SkipStmt())), false);
    ModifyMethodModifier opr = new ModifyMethodModifier(impl);
    assertNotNull(opr.getMethodImpl());
    ModifyClassModifier mcn = new ModifyClassModifier();
    mcn.setName("M.C");
    DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
    DeltaDecl dd = new DeltaDecl();
    dd.setName("MyDelta");
    dd.addDeltaAccess(acc);
    dd.addModuleModifier(mcn);
    mcn.addModifier(opr);
    mcn.setParent(dd);
    acc.setParent(dd);
    opr.setParent(mcn);
    sig.setParent(opr);
    CompilationUnit cu = model.getCompilationUnitList().getChild(0);
    cu.addDeltaDecl(dd);
    dd.setParent(cu);
    model.applyDelta(dd);
    assertEquals(1, cls.getMethods().getNumChild());
    assertEquals(2, cls.getMethod(0).getBlock().getNumChild());
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) MethodSig(abs.frontend.ast.MethodSig) ClassDecl(abs.frontend.ast.ClassDecl) MethodImpl(abs.frontend.ast.MethodImpl) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) DeltaAccess(abs.frontend.ast.DeltaAccess) Model(abs.frontend.ast.Model) Block(abs.frontend.ast.Block) List(abs.frontend.ast.List) DeltaDecl(abs.frontend.ast.DeltaDecl) SkipStmt(abs.frontend.ast.SkipStmt) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 5 with Block

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

the class LocationTypeInferrerExtension method getFarTypes.

private List<LocationType> getFarTypes(ASTNode<?> originatingNode) {
    HasCogs node = null;
    String prefix = "";
    if (precision == LocationTypingPrecision.GLOBAL_FAR) {
        node = originatingNode.getCompilationUnit().getModel();
        prefix = "G";
    }
    if (precision == LocationTypingPrecision.COMPILATION_UNIT_LOCAL_FAR) {
        node = originatingNode.getCompilationUnit();
        prefix = "U";
    }
    if (precision == LocationTypingPrecision.MODULE_LOCAL_FAR) {
        node = originatingNode.getModuleDecl();
        prefix = "M";
    }
    if (precision == LocationTypingPrecision.CLASS_LOCAL_FAR) {
        Decl d = originatingNode.getContextDecl();
        if (d instanceof ClassDecl) {
            node = d;
            prefix = "C";
        }
        Block b = originatingNode.getContextBlock();
        if (b instanceof MainBlock) {
            node = b;
            prefix = "C";
        }
    }
    if (precision == LocationTypingPrecision.METHOD_LOCAL_FAR) {
        Block b = originatingNode.getContextBlock();
        if (b != null) {
            node = b;
            prefix = "M";
        }
    }
    if (node == null) {
        return Collections.emptyList();
    }
    final List<LocationType> e = farTypes.get(node);
    if (e != null) {
        return e;
    } else {
        List<LocationType> result = new ArrayList<>();
        int numberOfNewCogs = node.getNumberOfNewCogExpr();
        if (numberOfNewCogs > THRESHOLD) {
            numberOfNewCogs = THRESHOLD;
        }
        for (int i = 0; i < numberOfNewCogs; i++) {
            result.add(LocationType.createParametricFar(prefix + i));
        }
        farTypes.put(node, result);
        return result;
    }
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) HasCogs(abs.frontend.analyser.HasCogs) Block(abs.frontend.ast.Block) MainBlock(abs.frontend.ast.MainBlock) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl) MainBlock(abs.frontend.ast.MainBlock) LocationType(abs.frontend.typechecker.locationtypes.LocationType)

Aggregations

Block (abs.frontend.ast.Block)11 MethodSig (abs.frontend.ast.MethodSig)6 MethodImpl (abs.frontend.ast.MethodImpl)5 DeltaDecl (abs.frontend.ast.DeltaDecl)4 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)4 VarUse (abs.frontend.ast.VarUse)4 AddMethodModifier (abs.frontend.ast.AddMethodModifier)3 ClassDecl (abs.frontend.ast.ClassDecl)3 DataTypeUse (abs.frontend.ast.DataTypeUse)3 MainBlock (abs.frontend.ast.MainBlock)3 ABSRef (apet.testCases.ABSRef)3 AbsASTBuilderUtil.createMethodSig (abs.backend.tests.AbsASTBuilderUtil.createMethodSig)2 Annotation (abs.frontend.ast.Annotation)2 CompilationUnit (abs.frontend.ast.CompilationUnit)2 DeltaAccess (abs.frontend.ast.DeltaAccess)2 FieldUse (abs.frontend.ast.FieldUse)2 InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)2 List (abs.frontend.ast.List)2 Model (abs.frontend.ast.Model)2 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)2