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;
}
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());
}
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;
}
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());
}
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;
}
}
Aggregations