use of de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition in project probparsers by bendisposto.
the class MachineContext method caseADefinitionsMachineClause.
/**
* Definitions
*/
@Override
public void caseADefinitionsMachineClause(ADefinitionsMachineClause node) {
definitionMachineClause = node;
DefinitionsSorter.sortDefinitions(node);
List<PDefinition> copy = node.getDefinitions();
/*
* The definitions are not in a predefined order. In particular
* definitions can depend on each other. First all definitions are added
* to the definitions context table. Then all definitions are visited.
*/
Collection<PDefinition> definitionsToRemove = new HashSet<PDefinition>();
for (PDefinition e : copy) {
if (e instanceof AExpressionDefinitionDefinition) {
AExpressionDefinitionDefinition def = (AExpressionDefinitionDefinition) e;
String name = def.getName().getText();
if (name.startsWith("ASSERT_LTL")) {
LTLFormulaVisitor visitor = new LTLFormulaVisitor(name, this);
visitor.parseDefinition(def);
this.ltlVisitors.add(visitor);
definitionsToRemove.add(def);
} else if (name.startsWith("ANIMATION_")) {
definitionsToRemove.add(def);
}
evalDefinitionName(((AExpressionDefinitionDefinition) e).getName().getText().toString(), e);
} else if (e instanceof APredicateDefinitionDefinition) {
evalDefinitionName(((APredicateDefinitionDefinition) e).getName().getText().toString(), e);
} else if (e instanceof ASubstitutionDefinitionDefinition) {
evalDefinitionName(((ASubstitutionDefinitionDefinition) e).getName().getText().toString(), e);
}
}
/*
* At this point all LTL definitions (ASSERT_LTL) are removed. LTL
* formulas are stored in the Arraylist {@value #ltlVisitors}.
*/
copy.removeAll(definitionsToRemove);
this.contextTable = new ArrayList<LinkedHashMap<String, Node>>();
ArrayList<MachineContext> list = lookupReferencedMachines();
for (int i = 0; i < list.size(); i++) {
MachineContext s = list.get(i);
contextTable.add(s.getDeferredSets());
contextTable.add(s.getEnumeratedSets());
contextTable.add(s.getEnumValues());
contextTable.add(s.getConstants());
contextTable.add(s.getVariables());
contextTable.add(s.getDefinitions());
}
for (PDefinition e : copy) {
e.apply(this);
}
}
use of de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition in project probparsers by bendisposto.
the class DefinitionCollector method inASubstitutionDefinitionDefinition.
@Override
public void inASubstitutionDefinitionDefinition(final ASubstitutionDefinitionDefinition node) {
final String defName = node.getName().getText();
final Type type = defTypes.getType(defName);
addDefinition(node, type, defName);
}
use of de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition in project probparsers by bendisposto.
the class ASTBuilder method addPrintSubDefinitionToIdefinitions.
public static void addPrintSubDefinitionToIdefinitions(IDefinitions definitions) {
if (definitions.containsDefinition(PRINT)) {
return;
}
/*-
* PRINT(x) == skip;
* EXTERNAL_SUBSTITUTION_PRINT(T) == T; /* declare as external for any type T
*/
ASubstitutionDefinitionDefinition printDef = new ASubstitutionDefinitionDefinition();
printDef.setName(new TDefLiteralSubstitution(PRINT));
printDef.setParameters(createIdentifierList("value"));
printDef.setRhs(new ASkipSubstitution());
definitions.addDefinition(printDef, IDefinitions.Type.Substitution);
AExpressionDefinitionDefinition forceDefType = new AExpressionDefinitionDefinition();
forceDefType.setName(new TIdentifierLiteral("EXTERNAL_SUBSTITUTION_" + PRINT));
forceDefType.setParameters(createIdentifierList("T"));
forceDefType.setRhs(createIdentifier("T"));
definitions.addDefinition(forceDefType, IDefinitions.Type.Expression);
}
use of de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition in project probparsers by bendisposto.
the class OpSubstitutions method setTypeSubstDef.
private void setTypeSubstDef(final AFuncOpSubstitution node, final String idString) {
final AExpressionDefinitionDefinition oldDefinition = (AExpressionDefinitionDefinition) definitions.getDefinition(idString);
final Node defRhs = oldDefinition.getRhs();
final PSubstitution rhsSubst;
if (defRhs instanceof AFunctionExpression) {
final AFunctionExpression rhsFunction = (AFunctionExpression) defRhs;
rhsSubst = new AOpSubstitution(rhsFunction.getIdentifier(), new LinkedList<PExpression>(rhsFunction.getParameters()));
rhsSubst.setStartPos(rhsFunction.getStartPos());
rhsSubst.setEndPos(rhsFunction.getEndPos());
} else if (defRhs instanceof AIdentifierExpression) {
final AIdentifierExpression rhsIdent = (AIdentifierExpression) defRhs;
rhsSubst = new AOpSubstitution(rhsIdent, new LinkedList<PExpression>());
rhsSubst.setStartPos(rhsIdent.getStartPos());
rhsSubst.setEndPos(rhsIdent.getEndPos());
} else {
// some other expression was parsed (NOT allowed)
throw new VisitorException(new CheckException("Expecting operation", node));
}
final TIdentifierLiteral oldDefId = oldDefinition.getName();
final TDefLiteralSubstitution defId = new TDefLiteralSubstitution(oldDefId.getText(), oldDefId.getLine(), oldDefId.getPos());
final ASubstitutionDefinitionDefinition substDef = new ASubstitutionDefinitionDefinition(defId, new LinkedList<PExpression>(oldDefinition.getParameters()), rhsSubst);
substDef.setStartPos(oldDefinition.getStartPos());
substDef.setEndPos(oldDefinition.getEndPos());
definitions.replaceDefinition(idString, Type.Substitution, substDef);
oldDefinition.replaceBy(substDef);
}
use of de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition in project probparsers by bendisposto.
the class RulesMachineChecker method caseASubstitutionDefinitionDefinition.
@Override
public void caseASubstitutionDefinitionDefinition(ASubstitutionDefinitionDefinition node) {
final String name = node.getName().getText();
this.definitions.add(name);
if ("GOAL".equals(name)) {
errorList.add(new CheckException("The GOAL definition must be a predicate.", node));
return;
}
this.identifierScope.createNewScope(new LinkedList<>(node.getParameters()));
node.getRhs().apply(this);
this.identifierScope.removeScope();
}
Aggregations