Search in sources :

Example 1 with PDefinition

use of de.be4.classicalb.core.parser.node.PDefinition 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);
    }
}
Also used : APredicateDefinitionDefinition(de.be4.classicalb.core.parser.node.APredicateDefinitionDefinition) ASubstitutionDefinitionDefinition(de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition) LinkedHashMap(java.util.LinkedHashMap) PDefinition(de.be4.classicalb.core.parser.node.PDefinition) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) HashSet(java.util.HashSet)

Example 2 with PDefinition

use of de.be4.classicalb.core.parser.node.PDefinition in project probparsers by bendisposto.

the class Definitions method assignIdsToNodes.

@Override
public void assignIdsToNodes(NodeIdAssignment nodeIdMapping, List<File> machineFilesLoaded) {
    if (file != null) {
        machineFilesLoaded.add(file);
        final int fileNumber = machineFilesLoaded.indexOf(file) + 1;
        for (PDefinition def : definitionsMap.values()) {
            nodeIdMapping.assignIdentifiers(fileNumber, def);
        }
    }
    for (IDefinitions defintions : super.referencedDefinitions) {
        defintions.assignIdsToNodes(nodeIdMapping, machineFilesLoaded);
    }
}
Also used : PDefinition(de.be4.classicalb.core.parser.node.PDefinition)

Example 3 with PDefinition

use of de.be4.classicalb.core.parser.node.PDefinition in project probparsers by bendisposto.

the class DefinitionCollector method addDefinition.

private void addDefinition(PDefinition def, Type type, String name) {
    if (definitions.containsDefinition(name)) {
        PDefinition existingDefinition = definitions.getDefinition(name);
        File file = definitions.getFile(name);
        StringBuilder sb = new StringBuilder();
        sb.append("Duplicate definition: " + name + ".\n");
        sb.append("(First appearance: ").append(this.getPosition(existingDefinition.getStartPos()));
        if (file != null) {
            sb.append(" in ").append(file.getAbsolutePath());
        }
        sb.append(")\n");
        CheckException e = new CheckException(sb.toString(), def);
        this.exceptions.add(e);
    } else {
        definitions.addDefinition(def, type, name);
    }
}
Also used : PDefinition(de.be4.classicalb.core.parser.node.PDefinition) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) File(java.io.File)

Example 4 with PDefinition

use of de.be4.classicalb.core.parser.node.PDefinition in project probparsers by bendisposto.

the class RulesProject method createMainMachine.

private BMachine createMainMachine(List<PDefinition> mainDefinitions) {
    BMachine mainMachine = new BMachine(MAIN_MACHINE_NAME);
    mainMachine.addIncludesClause(COMPOSITION_MACHINE_NAME);
    mainMachine.addPromotesClause(getPromotesList());
    mainMachine.addPropertiesPredicates(this.constantStringValues);
    IDefinitions idefinitions = new Definitions();
    if (mainDefinitions != null) {
        for (PDefinition pDefinition : mainDefinitions) {
            idefinitions.addDefinition(pDefinition);
        }
    }
    addToStringDefinition(idefinitions);
    addSortDefinition(idefinitions);
    addFormatToStringDefinition(idefinitions);
    addChooseDefinition(idefinitions);
    addBooleanPreferenceDefinition(idefinitions, "SET_PREF_ALLOW_LOCAL_OPERATION_CALLS", true);
    mainMachine.replaceDefinition(idefinitions);
    return mainMachine;
}
Also used : PDefinition(de.be4.classicalb.core.parser.node.PDefinition) Definitions(de.be4.classicalb.core.parser.Definitions) IDefinitions(de.be4.classicalb.core.parser.IDefinitions) IDefinitions(de.be4.classicalb.core.parser.IDefinitions)

Example 5 with PDefinition

use of de.be4.classicalb.core.parser.node.PDefinition in project probparsers by bendisposto.

the class DefinitionCollector method caseAConversionDefinition.

@Override
public void caseAConversionDefinition(AConversionDefinition node) {
    PDefinition def = node.getDefinition();
    if (def instanceof AExpressionDefinitionDefinition) {
        AExpressionDefinitionDefinition exprDef = (AExpressionDefinitionDefinition) def;
        final String defName = exprDef.getName().getText();
        final Type type = defTypes.getType(defName);
        addDefinition(node, type, defName);
    } else {
        this.exceptions.add(new CheckException("Only an expression is allowed on the right hand side of a conversion definition.", node));
    }
}
Also used : PDefinition(de.be4.classicalb.core.parser.node.PDefinition) Type(de.be4.classicalb.core.parser.IDefinitions.Type) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)

Aggregations

PDefinition (de.be4.classicalb.core.parser.node.PDefinition)5 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)2 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)2 Definitions (de.be4.classicalb.core.parser.Definitions)1 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)1 Type (de.be4.classicalb.core.parser.IDefinitions.Type)1 APredicateDefinitionDefinition (de.be4.classicalb.core.parser.node.APredicateDefinitionDefinition)1 ASubstitutionDefinitionDefinition (de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition)1 File (java.io.File)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1