use of abs.frontend.ast.PureExp in project abstools by abstools.
the class MaudeCompilerHelper method emitParameterValueList.
public static void emitParameterValueList(PrintStream stream, abs.frontend.ast.List<PureExp> params, java.util.List<Type> paramTypes) {
if (params.getNumChild() == 0) {
stream.print("emp ");
} else {
boolean inlist = false;
stream.print("(");
for (int i = 0; i < params.getNumChild(); i++) {
PureExp param = params.getChild(i);
Type t = paramTypes.get(i);
boolean needConversion = t.isIntType() && param.getType().isRatType();
if (inlist)
stream.print(":: ");
else
inlist = true;
if (needConversion)
stream.print("\"ABS.StdLib.truncate\"(");
param.generateMaude(stream);
if (needConversion)
stream.print(")");
}
stream.print(") ");
}
}
use of abs.frontend.ast.PureExp in project abstools by abstools.
the class TreeUtilsTest method findChildrenList.
@Test
public void findChildrenList() {
Model model = assertParseOkStdLib("def Int test(Int i) = test(1);");
FunctionDecl functionDecl = getLastFunctionDecl(model);
assertEquals("test", functionDecl.getName());
List<PureExp> children = functionDecl.getFunctionDef().findChildren(PureExp.class);
assertEquals(2, children.size());
}
use of abs.frontend.ast.PureExp in project abstools by abstools.
the class TreeUtilsTest method findChildrenMultipleTypes.
@Test
public void findChildrenMultipleTypes() {
Model model = assertParseOkStdLib("def Int test(Int i) = test(1);");
FunctionDecl functionDecl = getLastFunctionDecl(model);
assertEquals("test", functionDecl.getName());
FunctionDef def = functionDecl.getFunctionDef();
Stream<PureExp> children = def.findChildren(cast(ImmutableList.of(FnApp.class, IntLiteral.class)), n -> true);
assertNotNull(children);
List<PureExp> result = children.distinct().collect(Collectors.toList());
assertEquals(2, result.size());
for (PureExp exp : result) {
assertTrue(exp instanceof FnApp || exp instanceof IntLiteral);
}
}
use of abs.frontend.ast.PureExp 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.PureExp 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);
}
}
Aggregations