use of abs.frontend.ast.Stmt in project abstools by abstools.
the class ABSUnitTestCaseBuilder method makeSetStatements.
void makeSetStatements(Map<String, String> typeHierarchy, Map<String, List<Stmt>> initialisations, List<String> initialisationsOrders, String testName, Set<String> heapNames, Map<ABSRef, ABSObject> initialHeap, Map<String, InterfaceTypeUse> objectsInHeap, ABSRef ref, ABSObject state, ClassDecl testClass) {
String rn = heapRefBuilder.heapReferenceForTest(testName, getABSDataValue(ref));
String concreteTypeName = getABSObjectType(state);
ClassDecl concreteType = getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(concreteTypeName));
if (concreteType == null) {
throw new IllegalStateException("Cannot find class: " + concreteTypeName);
}
List<Stmt> statements = new ArrayList<Stmt>();
initialisations.put(rn, statements);
if (!initialisationsOrders.contains(rn)) {
initialisationsOrders.add(rn);
}
Map<String, ABSData> fields = getABSObjectFields(state);
abs.frontend.ast.List<ParamDecl> params = concreteType.getParamList();
PureExp[] constructorArgs = new PureExp[params.getNumChild()];
for (int i = 0; i < params.getNumChild(); i++) {
ParamDecl param = params.getChild(i);
String name = param.getName();
assert fields.containsKey(name);
ABSData d = fields.remove(name);
objectsInHeap.putAll(getTypesFromABSData(testName, d));
PureExp exp = pureExpBuilder.createPureExpression(rn, initialisationsOrders, testName, heapNames, d);
constructorArgs[i] = exp;
}
statements.add(getVAssign(rn, newObj(concreteType, false, constructorArgs)));
for (String fn : fields.keySet()) {
ABSData d = fields.get(fn);
objectsInHeap.putAll(getTypesFromABSData(testName, d));
PureExp exp = pureExpBuilder.createPureExpression(rn, initialisationsOrders, testName, heapNames, d);
Call call = getCall(new VarUse(rn), testCaseNameBuilder.setterMethodName(fn), true, exp);
statements.add(getExpStmt(call));
}
// ADD getter and setter
deltaBuilder.updateDelta(typeHierarchy, objectsInHeap.get(rn), getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(concreteTypeName)));
}
use of abs.frontend.ast.Stmt in project abstools by abstools.
the class SchedulerChecker method checkNewExp.
@Override
public void checkNewExp(NewExp e) {
Stmt stmt = CompilerUtils.findStmtForExpression(e);
PureExp sched = CompilerUtils.getAnnotationValueFromName(stmt.getAnnotations(), "ABS.Scheduler.Scheduler");
if (sched != null) {
ClassDecl decl = (ClassDecl) (e.lookup(new KindedName(KindedName.Kind.CLASS, e.getClassName())));
checkScheduleExp(sched, decl, stmt);
}
}
use of abs.frontend.ast.Stmt 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;
}
use of abs.frontend.ast.Stmt in project abstools by abstools.
the class FreeVarTest method fieldUse.
@Test
public void fieldUse() {
ClassDecl clazz = getFirstClassDecl(assertParseOkStdLib("class C {" + "Int i = 0;" + "Int m() {" + "return i + 1;" + "}" + "}"));
MethodImpl method = clazz.lookupMethod("m");
assertNotNull(method);
Stmt stmt = method.getBlock().getStmt(0);
assertTrue(stmt instanceof ReturnStmt);
ReturnStmt returnStmt = (ReturnStmt) stmt;
Exp exp = returnStmt.getRetExp();
assertEquals(exp.getFreeVars(), "i");
}
use of abs.frontend.ast.Stmt 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());
}
Aggregations