use of de.be4.classicalb.core.parser.node.AOperation in project probparsers by bendisposto.
the class MachineContext method caseAOperationsMachineClause.
@Override
public void caseAOperationsMachineClause(AOperationsMachineClause node) {
this.operationMachineClause = node;
this.contextTable = new ArrayList<LinkedHashMap<String, Node>>();
ArrayList<MachineContext> list = lookupReferencedMachines();
for (int i = 0; i < list.size(); i++) {
MachineContext s = list.get(i);
this.contextTable.add(s.getSetParamter());
this.contextTable.add(s.getScalarParameter());
this.contextTable.add(s.getDeferredSets());
this.contextTable.add(s.getEnumeratedSets());
this.contextTable.add(s.getEnumValues());
this.contextTable.add(s.getConstants());
this.contextTable.add(s.getDefinitions());
this.contextTable.add(s.getVariables());
}
List<POperation> copy = new ArrayList<POperation>(node.getOperations());
// first collect all operations
for (POperation e : copy) {
AOperation op = (AOperation) e;
String name = Utils.getTIdentifierListAsString(op.getOpName());
// existString(name);
if (operations.keySet().contains(name)) {
throw new ScopeException(String.format("Duplicate operation: '%s'", name));
}
operations.put(name, op);
}
// visit all operations
for (POperation e : copy) {
e.apply(this);
}
}
use of de.be4.classicalb.core.parser.node.AOperation in project probparsers by bendisposto.
the class CreateFreetypeTest method createSimpleAdd.
private AOperation createSimpleAdd(String name) {
final ASetExtensionExpression newVal = new ASetExtensionExpression(createIdentifiers(CONS_EMPTY));
final PSubstitution subst = createAssignment(VAR_NAME, new AUnionExpression(createIdentifier(VAR_NAME), newVal));
return new AOperation(EMPTY_EXPRS, createIdLits(name), EMPTY_EXPRS, subst);
}
use of de.be4.classicalb.core.parser.node.AOperation in project probparsers by bendisposto.
the class CreateFreetypeTest method createAdd.
private AOperation createAdd(String name, String param, PExpression type, String cons) {
final AMemberPredicate pre = new AMemberPredicate(createIdentifier(param), type);
final ASetExtensionExpression newVal = new ASetExtensionExpression(Arrays.<PExpression>asList(new AFunctionExpression(createIdentifier(cons), createIdentifiers(param))));
final PSubstitution subst = new APreconditionSubstitution(pre, createAssignment(VAR_NAME, new AUnionExpression(createIdentifier(VAR_NAME), newVal)));
return new AOperation(EMPTY_EXPRS, createIdLits(name), createIdentifiers(param), subst);
}
use of de.be4.classicalb.core.parser.node.AOperation in project probparsers by bendisposto.
the class CreateFreetypeTest method createOperations.
private AOperationsMachineClause createOperations() {
final AOperation op1 = createAdd("addBool", "b", new ABoolSetExpression(), CONS_BOOL);
final AOperation op2 = createAdd("addInt", "i", new AIntSetExpression(), CONS_INT);
final AOperation op3 = createSimpleAdd("addEmpty");
final AOperationsMachineClause operations = new AOperationsMachineClause(Arrays.<POperation>asList(op1, op2, op3));
return operations;
}
use of de.be4.classicalb.core.parser.node.AOperation in project prob2 by bendisposto.
the class DomBuilder method inAOperation.
@Override
public void inAOperation(final AOperation node) {
String name = extractIdentifierName(node.getOpName());
if (prefix != null && !prefix.equals(name)) {
name = prefix + "." + name;
}
List<PExpression> paramIds = node.getParameters();
final List<String> params = extractIdentifiers(paramIds);
final List<String> output = extractIdentifiers(node.getReturnValues());
Operation operation = new Operation(name, params, output);
PSubstitution body = node.getOperationBody();
List<ClassicalBGuard> guards = new ArrayList<>();
if (body instanceof ASelectSubstitution) {
PPredicate condition = ((ASelectSubstitution) body).getCondition();
List<PPredicate> predicates = getPredicates(condition);
for (PPredicate pPredicate : predicates) {
guards.add(new ClassicalBGuard(createPredicateAST(pPredicate)));
}
}
if (body instanceof APreconditionSubstitution) {
PPredicate condition = ((APreconditionSubstitution) body).getPredicate();
List<PPredicate> predicates = getPredicates(condition);
for (PPredicate pPredicate : predicates) {
guards.add(new ClassicalBGuard(createPredicateAST(pPredicate)));
}
}
List<ClassicalBAction> actions = new ArrayList<>();
actions.add(new ClassicalBAction(createSubstitutionAST(body)));
operation = operation.set(Action.class, new ModelElementList<>(actions));
operation = operation.set(Guard.class, new ModelElementList<>(guards));
operations.add(operation);
}
Aggregations