Search in sources :

Example 1 with Forall

use of com.ge.research.osate.verdict.dsl.verdict.Forall in project VERDICT by ge-high-assurance.

the class ThreatModelUtil method getScope.

/**
 * Get all variables in scope for an expression.
 *
 * Searches up the AST for variable introductions, starting from the
 * immediate parent of obj.
 *
 * Note that if scoping a quantification, you cannot pass the object
 * directly because this might include the newly-introduced variable
 * in its own scope! See getContainerForClasses() for obtaining the
 * correct parent to use for scoping.
 *
 * @param obj the context for which to find scope.
 * @param indexProvider the index provider, may be obtained from Guice
 * @return the list of variables that are in scope
 */
public static List<VerdictVariable> getScope(EObject obj, ResourceDescriptionsProvider indexProvider) {
    // Get type information
    LinkedHashMap<String, VerdictType> types = getTypes(obj, indexProvider);
    List<VerdictVariable> vars = new ArrayList<>();
    // Traverse upward until we find the enclosing threat model
    while (!(obj instanceof ThreatModel || obj == null)) {
        obj = obj.eContainer();
        if (obj instanceof ThreatModel) {
            // Threat model introduces a system
            ThreatModel threatModel = (ThreatModel) obj;
            vars.add(VerdictVariableImpl.fromIntro(threatModel.getIntro(), types));
        } else if (obj instanceof Forall) {
            // Forall introduces a variable
            Forall forall = (Forall) obj;
            vars.add(VerdictVariableImpl.fromIntro(forall.getIntro(), types));
        } else if (obj instanceof Exists) {
            // Exists introduces a variable
            Exists exists = (Exists) obj;
            vars.add(VerdictVariableImpl.fromIntro(exists.getIntro(), types));
        }
    }
    return vars;
}
Also used : VerdictType(com.ge.research.osate.verdict.dsl.type.VerdictType) Exists(com.ge.research.osate.verdict.dsl.verdict.Exists) ArrayList(java.util.ArrayList) VerdictVariable(com.ge.research.osate.verdict.dsl.type.VerdictVariable) Forall(com.ge.research.osate.verdict.dsl.verdict.Forall) ThreatModel(com.ge.research.osate.verdict.dsl.verdict.ThreatModel)

Aggregations

VerdictType (com.ge.research.osate.verdict.dsl.type.VerdictType)1 VerdictVariable (com.ge.research.osate.verdict.dsl.type.VerdictVariable)1 Exists (com.ge.research.osate.verdict.dsl.verdict.Exists)1 Forall (com.ge.research.osate.verdict.dsl.verdict.Forall)1 ThreatModel (com.ge.research.osate.verdict.dsl.verdict.ThreatModel)1 ArrayList (java.util.ArrayList)1