Search in sources :

Example 1 with BasicAction

use of org.osate.ba.aadlba.BasicAction in project osate2 by osate.

the class AadlBaNameResolver method behaviorActionResolver.

private boolean behaviorActionResolver(BehaviorAction act) {
    boolean result = true;
    // Case of basic action.
    if (act instanceof BasicAction) {
        result = basicActionResolver((BasicAction) act);
    } else {
        if (act instanceof BehaviorActionBlock) {
            result = behaviorActionBlockResolver((BehaviorActionBlock) act);
        } else {
            // Case of IF statement.
            if (act instanceof IfStatement) {
                result = ifStatementResolver((IfStatement) act);
            } else {
                // Case if WHILE and DO UNTIL statement.
                if (act instanceof WhileOrDoUntilStatement) {
                    WhileOrDoUntilStatement stat = (WhileOrDoUntilStatement) act;
                    result = valueExpressionResolver(stat.getLogicalValueExpression());
                    result &= behaviorActionsResolver(stat.getBehaviorActions());
                } else // Case of FOR and FOR ALL statement.
                {
                    ForOrForAllStatement stat = (ForOrForAllStatement) act;
                    IterativeVariable itVar = stat.getIterativeVariable();
                    // Resolves unique component classifier reference.
                    QualifiedNamedElement uccr = (QualifiedNamedElement) itVar.getDataClassifier();
                    result = qualifiedNamedElementResolver(uccr, true);
                    // Checks the for/forall's iterative variable.
                    result &= iterativeVariableUniquenessCheck(itVar);
                    // Add the for/forall statment's iterative variable to
                    // the scope handler.
                    _itvScope.add(itVar);
                    // Check element values.
                    result &= elementValuesResolver(stat.getIteratedValues());
                    // Check behavior actions.
                    result &= behaviorActionsResolver(stat.getBehaviorActions());
                    // remove the for/forall statment's iterative variable from
                    // the scope handler (after checking for/forall's behavior
                    // actions.
                    _itvScope.remove(itVar);
                }
            }
        // End of third else.
        }
    // End of second else.
    }
    return result;
}
Also used : IfStatement(org.osate.ba.aadlba.IfStatement) IterativeVariable(org.osate.ba.aadlba.IterativeVariable) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) BasicAction(org.osate.ba.aadlba.BasicAction) WhileOrDoUntilStatement(org.osate.ba.aadlba.WhileOrDoUntilStatement) BehaviorActionBlock(org.osate.ba.aadlba.BehaviorActionBlock) ForOrForAllStatement(org.osate.ba.aadlba.ForOrForAllStatement)

Example 2 with BasicAction

use of org.osate.ba.aadlba.BasicAction in project osate2 by osate.

the class AadlBaLegalityRulesChecker method buildActionSetAssignedTargetLists.

/**
 * Recursively builds a list of assigned target contained
 * in a given BehaviorActions tree and checks for duplicated targets every time
 * it meet a Behavior Action Set node. It populates the given set with
 * duplicated targets.<BR><BR>
 *
 * A special attention is given to report legality rules D.6.(L3) and (L4)
 * failures : in order to help the user to correct his errors, the duplicates
 * list contains all instances of duplicated assigned targets.
 *
 * @param beActions The given BehaviorActions tree.
 * @param lActionSetDcr The list of assigned targets
 * @param lDuplicates The set of duplicated assigned targets.
 */
// As Java 1.6 can't create generic array.
@SuppressWarnings("unchecked")
private void buildActionSetAssignedTargetLists(BehaviorActions beActions, List<Target> lActionSetTar, Set<Target> lDuplicates) {
    // Basic action cases.
    if (beActions instanceof BasicAction) {
        if (beActions instanceof AssignmentAction) {
            lActionSetTar.add(((AssignmentAction) beActions).getTarget());
        }
        return;
    }
    // Behavior Action Block case.
    if (beActions instanceof BehaviorActionBlock) {
        BehaviorActionBlock tmp = (BehaviorActionBlock) beActions;
        buildActionSetAssignedTargetLists(tmp.getContent(), lActionSetTar, lDuplicates);
        return;
    }
    // If Statement case.
    if (beActions instanceof IfStatement) {
        IfStatement ifStat = (IfStatement) beActions;
        BehaviorActions tmp = ifStat.getBehaviorActions();
        buildActionSetAssignedTargetLists(tmp, lActionSetTar, lDuplicates);
        if (ifStat.getElseStatement() != null) {
            tmp = ifStat.getElseStatement();
            buildActionSetAssignedTargetLists(tmp, lActionSetTar, lDuplicates);
        }
        return;
    }
    if (beActions instanceof ElseStatement) {
        ElseStatement elseStat = (ElseStatement) beActions;
        BehaviorActions tmp = elseStat.getBehaviorActions();
        buildActionSetAssignedTargetLists(tmp, lActionSetTar, lDuplicates);
        return;
    }
    // Loop Statement case.
    if (beActions instanceof LoopStatement) {
        LoopStatement tmp = (LoopStatement) beActions;
        buildActionSetAssignedTargetLists(tmp.getBehaviorActions(), lActionSetTar, lDuplicates);
        return;
    }
    // ***** Processing containers:
    // List of BehaviorAction objects contained in the given BehaviorActions
    // tree.
    List<BehaviorAction> lbeActs = ((BehaviorActionCollection) beActions).getActions();
    // Behavior Action Sequence case:
    if (beActions instanceof BehaviorActionSequence) {
        for (BehaviorAction tmp : lbeActs) {
            buildActionSetAssignedTargetLists(tmp, lActionSetTar, lDuplicates);
        }
        return;
    }
    // Behavior Action Set case:
    // Current BehaviorAction object.
    BehaviorAction behAct;
    // Creates an array which will handle the lists of assigned targets. One
    // list for each behavior action of the action set.
    List<Target>[] llActionSetTar = null;
    llActionSetTar = new List[lbeActs.size()];
    // For each BehaviorAction of the given BehaviorActionCollection.
    for (int i = 0; i < lbeActs.size(); i++) {
        behAct = lbeActs.get(i);
        llActionSetTar[i] = new ArrayList<Target>();
        buildActionSetAssignedTargetLists(behAct, llActionSetTar[i], lDuplicates);
    }
    // Check for duplicated assigned targets in the lists of the
    // action set. Complexity is O(n^2) as the lists are not sorted.
    List<Target> lCurrent = null;
    List<Target> lOther = null;
    // Optimization flag to avoid adding the same target to the duplicates
    // set.
    boolean hasToAdd = true;
    // Compare the lists between them.
    for (int i = 0; i < llActionSetTar.length - 1; i++) {
        lCurrent = llActionSetTar[i];
        for (Target currentTar : lCurrent) {
            // Compare current list with the others.
            for (int j = i + 1; j < llActionSetTar.length; j++) {
                lOther = llActionSetTar[j];
                for (Target otherTar : lOther) {
                    // Case of duplicated assigned target.
                    if (AadlBaUtils.isSameTarget(currentTar, otherTar)) {
                        // Add the current target if it hasn't be done yet.
                        if (hasToAdd) {
                            lDuplicates.add(currentTar);
                            hasToAdd = false;
                        }
                        // Add the other target to help the user finding his errors.
                        lDuplicates.add(otherTar);
                    }
                }
            }
            // Reset the flag for the next target.
            hasToAdd = true;
        }
    }
    // higher level action set checking.
    for (List<Target> l : llActionSetTar) {
        lActionSetTar.addAll(l);
    }
}
Also used : BasicAction(org.osate.ba.aadlba.BasicAction) AssignmentAction(org.osate.ba.aadlba.AssignmentAction) LoopStatement(org.osate.ba.aadlba.LoopStatement) IfStatement(org.osate.ba.aadlba.IfStatement) Target(org.osate.ba.aadlba.Target) BehaviorAction(org.osate.ba.aadlba.BehaviorAction) BehaviorActionCollection(org.osate.ba.aadlba.BehaviorActionCollection) ElseStatement(org.osate.ba.aadlba.ElseStatement) BehaviorActionBlock(org.osate.ba.aadlba.BehaviorActionBlock) BehaviorActions(org.osate.ba.aadlba.BehaviorActions) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) BehaviorActionSequence(org.osate.ba.aadlba.BehaviorActionSequence)

Aggregations

BasicAction (org.osate.ba.aadlba.BasicAction)2 BehaviorActionBlock (org.osate.ba.aadlba.BehaviorActionBlock)2 IfStatement (org.osate.ba.aadlba.IfStatement)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 AssignmentAction (org.osate.ba.aadlba.AssignmentAction)1 BehaviorAction (org.osate.ba.aadlba.BehaviorAction)1 BehaviorActionCollection (org.osate.ba.aadlba.BehaviorActionCollection)1 BehaviorActionSequence (org.osate.ba.aadlba.BehaviorActionSequence)1 BehaviorActions (org.osate.ba.aadlba.BehaviorActions)1 ElseStatement (org.osate.ba.aadlba.ElseStatement)1 ForOrForAllStatement (org.osate.ba.aadlba.ForOrForAllStatement)1 IterativeVariable (org.osate.ba.aadlba.IterativeVariable)1 LoopStatement (org.osate.ba.aadlba.LoopStatement)1 Target (org.osate.ba.aadlba.Target)1 WhileOrDoUntilStatement (org.osate.ba.aadlba.WhileOrDoUntilStatement)1 QualifiedNamedElement (org.osate.ba.declarative.QualifiedNamedElement)1