Пример #1
0
        /// <summary>
        /// Checks the compatibility of all updates
        /// </summary>
        /// <param name="variableUpdates"></param>
        public void CheckUpdatesCompatibility(IEnumerable <VariableUpdate> variableUpdates)
        {
            if (CheckForCompatibleChanges)
            {
                // Holds all changes that have already been processed
                Dictionary <IVariable, Change>      changes   = new Dictionary <IVariable, Change>();
                Dictionary <Change, VariableUpdate> traceBack = new Dictionary <Change, VariableUpdate>();

                foreach (VariableUpdate variableUpdate in variableUpdates)
                {
                    Action action = variableUpdate.Action;

                    ChangeList actionChanges = variableUpdate.Changes;
                    if (variableUpdate.Action.Statement is ProcedureCallStatement)
                    {
                        Dictionary <IVariable, Change> procedureChanges = new Dictionary <IVariable, Change>();

                        foreach (Change change in variableUpdate.Changes.Changes)
                        {
                            procedureChanges[change.Variable] = change;
                        }

                        actionChanges = new ChangeList();
                        foreach (Change change in procedureChanges.Values)
                        {
                            actionChanges.Add(change, false, this);
                        }
                    }

                    foreach (Change change in actionChanges.Changes)
                    {
                        IVariable variable = change.Variable;
                        if (changes.ContainsKey(change.Variable))
                        {
                            Change otherChange = changes[change.Variable];
                            Action otherAction = traceBack[otherChange].Action;
                            if (!variable.Type.CompareForEquality(otherChange.NewValue, change.NewValue))
                            {
                                if (change.CheckForCompatibility() || otherChange.CheckForCompatibility())
                                {
                                    string action1 = ((INamable)action.Enclosing).FullName + " : " +
                                                     variableUpdate.Action.FullName;
                                    string action2 = ((INamable)otherAction.Enclosing).FullName + " : " +
                                                     traceBack[otherChange].Action.FullName;
                                    variableUpdate.Action.AddError(
                                        "Simultaneous change of the variable " + variable.FullName +
                                        " with different values. Conflit between\n" +
                                        action1 + "\n and \n" + action2);
                                    action.AddError("Conflicting change");
                                    otherAction.AddError("Conflicting change");
                                }
                            }
                        }
                        else
                        {
                            changes.Add(change.Variable, change);
                            traceBack.Add(change, variableUpdate);
                        }
                    }
                }
            }
        }