use of abs.frontend.ast.VarUse 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.VarUse 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.VarUse in project abstools by abstools.
the class ABSUnitTestCaseBuilder method makeGetAndAssertStatementsForHeapRef.
void makeGetAndAssertStatementsForHeapRef(String testName, Set<String> heapNames, Map<ABSRef, ABSObject> finalHeap, ABSRef ref, ABSObject state, Set<String> visited, Block block) {
String rn = heapRefBuilder.heapReferenceForTest(testName, getABSDataValue(ref));
if (!visited.add(rn)) {
return;
}
Map<String, ABSData> fields = getABSObjectFields(state);
ClassDecl clazz = getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(getABSObjectType(state)));
abs.frontend.ast.List<FieldDecl> fieldDecls = clazz.getFieldList();
for (int i = 0; i < fieldDecls.getNumChild(); i++) {
FieldDecl field = fieldDecls.getChild(i);
String fn = field.getName();
if (fields.containsKey(fn)) {
ABSData d = fields.get(fn);
block.addStmtNoTransform(getVarDecl(testCaseNameBuilder.resultOfGetterMethodName(fn), field.getAccess().treeCopyNoTransform(), getCall(new VarUse(rn), testCaseNameBuilder.getterMethodName(fn), true)));
makeOracle(testName, heapNames, finalHeap, testCaseNameBuilder.resultOfGetterMethodName(fn), field.getAccess().treeCopyNoTransform(), d, visited, block);
}
}
}
use of abs.frontend.ast.VarUse 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.VarUse in project abstools by abstools.
the class PureExpressionBuilder method createPureExpression.
/**
* @param currentHeapReference
* @param initialisationsOrders
* @param heapNames
* @param dataValue
* @return
*/
PureExp createPureExpression(String currentHeapReference, List<String> initialisationsOrders, String testName, Set<String> heapNames, ABSData dataValue) {
String type = getABSDataType(dataValue);
String value = getABSDataValue(dataValue);
if (type.contains("(") && dataValue instanceof ABSTerm) {
ABSTerm term = (ABSTerm) dataValue;
type = getABSTermTypeName(term);
}
// import type
Decl decl = getDecl(model, Decl.class, namePred(type));
importType(decl);
if (dataValue instanceof ABSTerm) {
ABSTerm term = (ABSTerm) dataValue;
return makeDataTermValue(currentHeapReference, initialisationsOrders, testName, heapNames, term, decl);
} else if (dataValue instanceof ABSRef) {
if (heapNames.contains(value)) {
String ref = heapRefBuilder.heapReferenceForTest(testName, value);
if (currentHeapReference != null) {
// we need to consider initialisation order!
updateInitialisationOrder(initialisationsOrders, currentHeapReference, ref);
}
return new VarUse(ref);
} else {
return new NullExp();
}
} else {
throw new IllegalStateException("Cannot handle ABSData that is not " + "either a ABSRef or a ABSTerm");
}
}
Aggregations