Ejemplo n.º 1
0
        public override bool CompareForEquality(Values.IValue left, Values.IValue right)  // left == right
        {
            bool retVal = base.CompareForEquality(left, right);

            if (!retVal)
            {
                if (left.Type == right.Type)
                {
                    Values.StructureValue leftValue  = left as Values.StructureValue;
                    Values.StructureValue rightValue = right as Values.StructureValue;

                    if (left != null && right != null)
                    {
                        retVal = true;

                        foreach (KeyValuePair <string, Variables.IVariable> pair in leftValue.SubVariables)
                        {
                            Variables.IVariable leftVar  = pair.Value;
                            Variables.IVariable rightVar = rightValue.getVariable(pair.Key);

                            if (leftVar.Type != null)
                            {
                                retVal = leftVar.Type.CompareForEquality(leftVar.Value, rightVar.Value);
                                if (!retVal)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Indicates whether the expression is based on a placeholder value, ommiting the parameter provided
        /// </summary>
        /// <param name="context">The current interpretation context</param>
        /// <param name="expression">The expression to evaluate</param>
        /// <returns></returns>
        private bool ExpressionBasedOnPlaceHolder(Interpreter.InterpretationContext context, Interpreter.BinaryExpression expression)
        {
            bool retVal = false;

            if (expression != null)
            {
                foreach (Types.ITypedElement element in expression.GetRightSides())
                {
                    Parameter parameter = element as Parameter;
                    if (parameter != null)
                    {
                        Variables.IVariable variable = context.findOnStack(parameter);
                        if (variable != null)
                        {
                            Values.PlaceHolder placeHolder = variable.Value as Values.PlaceHolder;

                            if (placeHolder != null)
                            {
                                retVal = true;
                                break;
                            }
                        }
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Provides the graph of this function if it has been statically defined
        /// </summary>
        /// <param name="context">the context used to create the graph</param>
        /// <returns></returns>
        public virtual Graph createGraph(Interpreter.InterpretationContext context, Parameter parameter)
        {
            Graph retVal = Graph;

            if (retVal == null)
            {
                try
                {
                    Interpreter.InterpretationContext ctxt = new Interpreter.InterpretationContext(context);
                    if (Cases.Count > 0)
                    {
                        // For now, just create graphs for functions using 0 or 1 parameter.
                        if (FormalParameters.Count == 0)
                        {
                            Values.IValue value = Evaluate(ctxt, new Dictionary <Variables.Actual, Values.IValue>());
                            retVal = Graph.createGraph(value, parameter);
                        }
                        else if (FormalParameters.Count == 1)
                        {
                            Parameter     param       = (Parameter)FormalParameters[0];
                            int           token       = ctxt.LocalScope.PushContext();
                            Values.IValue actualValue = null;
                            if (parameter != null)
                            {
                                Variables.IVariable actual = ctxt.findOnStack(parameter);
                                if (actual != null)
                                {
                                    actualValue = actual.Value;
                                }
                                else
                                {
                                    actualValue = new Values.PlaceHolder(parameter.Type, 1);
                                }

                                ctxt.LocalScope.setParameter(param, actualValue);
                            }
                            retVal = createGraphForParameter(ctxt, param);

                            if (getCacheable() && actualValue is Values.PlaceHolder)
                            {
                                Graph = retVal;
                            }

                            ctxt.LocalScope.PopContext(token);
                        }
                        else
                        {
                            Values.IValue value = Evaluate(ctxt, new Dictionary <Variables.Actual, Values.IValue>());
                            retVal = Graph.createGraph(value, parameter);
                        }
                    }
                }
                catch (Exception e)
                {
                    AddError("Cannot create graph of function, reason : " + e.Message);
                }
            }

            return(retVal);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="variable"></param>
 /// <param name="previousValue"></param>
 /// <param name="newValue"></param>
 public Change(Variables.IVariable variable, Values.IValue previousValue, Values.IValue newValue)
 {
     Variable      = variable;
     PreviousValue = previousValue;
     NewValue      = newValue;
     Applied       = false;
 }
        /// <summary>
        /// Stores the variable in this symbol table
        /// </summary>
        /// <param name="variable"></param>
        public void setVariable(Variables.IVariable variable)
        {
            if (variable == null)
            {
                System.Diagnostics.Debugger.Break();
            }

            Values.Add(variable);
        }
Ejemplo n.º 6
0
        public Variables.IVariable GetVariable(InterpretationContext context)
        {
            Variables.IVariable retVal = null;

            INamable reference = getReference(context);

            retVal = reference as Variables.IVariable;

            return(retVal);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Provides the reference for this subdeclarator
        /// </summary>
        /// <param name="subDeclarator"></param>
        /// <returns></returns>
        private INamable getReferenceBySubDeclarator(ISubDeclarator subDeclarator)
        {
            INamable retVal = null;

            List <INamable> tmp = new List <INamable>();

            subDeclarator.Find(Image, tmp);
            if (tmp.Count > 0)
            {
                // Remove duplicates
                List <INamable> tmp2 = new List <INamable>();
                foreach (INamable namable in tmp)
                {
                    bool found = false;
                    foreach (INamable other in tmp2)
                    {
                        if (namable == other)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        tmp2.Add(namable);

                        // Consistency check.
                        Variables.IVariable subDeclVar = subDeclarator as Variables.Variable;
                        if (subDeclVar != null)
                        {
                            if (((IEnclosed)namable).Enclosing != subDeclVar.Value)
                            {
                                AddError("Consistency check failed : enclosed element's father relationship is inconsistent");
                            }
                        }
                        else
                        {
                            if (((IEnclosed)namable).Enclosing != subDeclarator)
                            {
                                AddError("Consistency check failed : enclosed element's father relationship is inconsistent");
                            }
                        }
                    }
                }

                // Provide the result, if it is unique
                if (tmp2.Count == 1)
                {
                    retVal = tmp2[0];
                }
            }

            return(retVal);
        }
        /// <summary>
        /// Gets the value associated to a name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Variables.IVariable getVariable(string name)
        {
            Variables.IVariable retVal = null;

            if (Val.ContainsKey(name))
            {
                retVal = Val[name] as Variables.IVariable;
            }

            return(retVal);
        }
        /// <summary>
        /// Provides the changes performed by this statement
        /// </summary>
        /// <param name="context">The context on which the changes should be computed</param>
        /// <param name="changes">The list to fill with the changes</param>
        /// <param name="explanation">The explanatino to fill, if any</param>
        /// <param name="apply">Indicates that the changes should be applied immediately</param>
        public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply)
        {
            Variables.IVariable variable = ListExpression.GetVariable(context);
            if (variable != null)
            {
                // HacK : ensure that the value is a correct rigth side
                // and keep the result of the right side operation
                Values.ListValue listValue = variable.Value.RightSide(variable, false) as Values.ListValue;
                variable.Value = listValue;
                if (listValue != null)
                {
                    Values.ListValue newListValue = new Values.ListValue(listValue);

                    int i = 0;
                    foreach (Values.IValue current in newListValue.Val)
                    {
                        IteratorVariable.Value = current;
                        if (conditionSatisfied(context))
                        {
                            break;
                        }
                        i += 1;
                    }

                    if (i < newListValue.Val.Count)
                    {
                        Values.IValue value = Value.GetValue(context);
                        if (value != null)
                        {
                            newListValue.Val[i] = value;
                            Rules.Change change = new Rules.Change(variable, variable.Value, newListValue);
                            changes.Add(change, apply);
                            explanation.SubExplanations.Add(new ExplanationPart(Root, change));
                        }
                        else
                        {
                            Root.AddError("Cannot find value for " + Value.ToString());
                        }
                    }
                    else
                    {
                        Root.AddError("Cannot find value in " + ListExpression.ToString() + " which satisfies " + Condition.ToString());
                    }
                }
                else
                {
                    Root.AddError("Variable " + ListExpression.ToString() + " does not contain a list value");
                }
            }
            else
            {
                Root.AddError("Cannot find variable for " + ListExpression.ToString());
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a valid right side IValue, according to the target variable (left side)
        /// </summary>
        /// <param name="variable">The target variable</param>
        /// <param name="duplicate">Indicates that a duplication of the variable should be performed</param>
        /// <returns></returns>
        public virtual Values.IValue RightSide(Variables.IVariable variable, bool duplicate)
        {
            State retVal = this;

            while (retVal.StateMachine.AllValues.Count > 0)
            {
                retVal = (Constants.State)retVal.StateMachine.DefaultValue;
            }

            return(retVal);
        }
        /// <summary>
        /// Creates a valid right side IValue, according to the target variable (left side)
        /// </summary>
        /// <param name="variable">The target variable</param>
        /// <param name="duplicate">Indicates that a duplication of the variable should be performed</param>
        /// <returns></returns>
        public override Values.IValue RightSide(Variables.IVariable variable, bool duplicate)
        {
            StructureValue retVal = this;

            if (duplicate)
            {
                retVal = new StructureValue(retVal);
            }
            retVal.Enclosing = variable;

            return(retVal);
        }
 /// <summary>
 /// Sets the value of a given association
 /// </summary>
 /// <param name="name"></param>
 /// <param name="val"></param>
 public void set(Variables.IVariable variable)
 {
     if (Val.ContainsKey(variable.Name))
     {
         Variables.IVariable var = Val[variable.Name] as Variables.IVariable;
         if (var != null)
         {
             var.Value = variable.Value;
         }
     }
     else
     {
         Val.Add(variable.Name, variable);
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Indicates that the change list modifies the variable provided as parameter
        /// </summary>
        /// <param name="variable"></param>
        /// <returns></returns>
        public bool ImpactVariable(Variables.IVariable variable)
        {
            bool retVal = false;

            foreach (Change change in Changes)
            {
                if (change.Variable == variable)
                {
                    retVal = true;
                    break;
                }
            }

            return(retVal);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Provides the variable referenced by this expression, if any
        /// </summary>
        /// <param name="context">The context on which the variable must be found</param>
        /// <returns></returns>
        public override Variables.IVariable GetVariable(InterpretationContext context)
        {
            Variables.IVariable retVal = null;

            if (Term != null)
            {
                retVal = Term.GetVariable(context);
            }
            else
            {
                AddError("Cannot get variable from expression" + ToString());
            }

            return(retVal);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Provides the variable referenced by this expression, if any
        /// </summary>
        /// <param name="context">The context on which the variable must be found</param>
        /// <returns></returns>
        public Variables.IVariable GetVariable(InterpretationContext context)
        {
            Variables.IVariable retVal = null;

            if (Designator != null)
            {
                retVal = Designator.GetVariable(context);
            }
            else if (LiteralValue != null)
            {
                retVal = null;
            }

            return(retVal);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Indicates that the rule fired impacts the variable provided as parameter
        /// </summary>
        /// <param name="variable"></param>
        /// <returns></returns>
        public bool ImpactVariable(Variables.IVariable variable)
        {
            bool retVal = false;

            foreach (VariableUpdate variableUpdate in Updates)
            {
                retVal = variableUpdate.Changes.ImpactVariable(variable);
                if (retVal)
                {
                    break;
                }
            }

            return(retVal);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Provides the variable assocaited to the name provided
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Variables.IVariable getVariable(string name)
        {
            Variables.IVariable retVal = null;

            for (int i = Values.Count - 1; i >= 0; i--)
            {
                Variables.IVariable element = Values[i];
                if (element.Name.CompareTo(name) == 0)
                {
                    retVal = element;
                    break;
                }
            }

            return(retVal);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Provides the actual variable which corresponds to this parameter on the stack
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public Variables.IVariable find(Parameter parameter)
        {
            Variables.IVariable retVal = null;

            for (int i = Values.Count - 1; i >= 0; i--)
            {
                Variables.IVariable var = Values[i];
                if (parameter.Name.Equals(var.Name))
                {
                    retVal = var;
                    break;
                }
            }

            return(retVal);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Provides the set of rules which uses this variable
        /// </summary>
        /// <param name="node">the element to find in rules</param>
        /// <returns>the list of rules which use the element provided</returns>
        public static HashSet <Rules.RuleCondition> RulesUsingThisElement(Variables.IVariable node)
        {
            UsageVisitor visitor = new UsageVisitor(node);

            EFSSystem efsSystem = Utils.EnclosingFinder <EFSSystem> .find(node);

            if (efsSystem != null)
            {
                foreach (Dictionary dictionary in efsSystem.Dictionaries)
                {
                    visitor.visit(dictionary);
                }
            }

            return(visitor.Usages);
        }
Ejemplo n.º 20
0
        public override Graph createGraph(Interpreter.InterpretationContext context, Parameter parameter)
        {
            Graph retVal = null;

            Variables.IVariable variable = context.findOnStack(Value);

            if (variable != null)
            {
                retVal = Graph.createGraph(Functions.Function.getDoubleValue(variable.Value), parameter);
            }
            else
            {
                AddError("Cannot find variable " + Value + " on the stack");
            }

            return(retVal);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Creates a valid right side IValue, according to the target variable (left side)
        /// </summary>
        /// <param name="variable">The target variable</param>
        /// <param name="duplicate">Indicates that a duplication of the variable should be performed</param>
        /// <returns></returns>
        public override Values.IValue RightSide(Variables.IVariable variable, bool duplicate)
        {
            ListValue retVal = this;

            //  Complete the list with empty values
            Types.Collection collectionType = variable.Type as Types.Collection;
            if (collectionType != null)
            {
                Values.EmptyValue emptyValue = EFSSystem.EmptyValue;
                while (retVal.Val.Count < collectionType.getMaxSize())
                {
                    retVal.Val.Add(emptyValue);
                }
            }
            retVal.Enclosing = variable;

            return(retVal);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Provides the variables used by this expression
        /// </summary>
        public List <Variables.IVariable> GetVariables()
        {
            List <Variables.IVariable> retVal = new List <Variables.IVariable>();

            List <Utils.INamable> tmp = new List <Utils.INamable>();

            fill(tmp, Filter.IsVariable);

            foreach (Utils.INamable namable in tmp)
            {
                Variables.IVariable variable = namable as Variables.IVariable;
                if (variable != null)
                {
                    retVal.Add(variable);
                }
            }

            return(retVal);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Provides the changes performed by this statement
 /// </summary>
 /// <param name="context">The context on which the changes should be computed</param>
 /// <param name="changes">The list to fill with the changes</param>
 /// <param name="explanation">The explanatino to fill, if any</param>
 /// <param name="apply">Indicates that the changes should be applied immediately</param>
 public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply)
 {
     Variables.IVariable var = VariableIdentification.GetVariable(context);
     if (var != null)
     {
         string        tmp   = var.FullName;
         Values.IValue value = Expression.GetValue(context);
         if (value != null)
         {
             value = value.RightSide(var, true);
         }
         Rules.Change change = new Rules.Change(var, var.Value, value);
         changes.Add(change, apply);
         explanation.SubExplanations.Add(new ExplanationPart(Root, change));
     }
     else
     {
         AddError("Cannot find variable " + VariableIdentification.ToString());
     }
 }
        /// <summary>
        /// Gets the unbound parameters from the function definition and place holders
        /// </summary>
        /// <param name="context"></param>
        /// <param name="function"></param>
        /// <returns></returns>
        private List <Parameter> getUnboundParameter(InterpretationContext context, Functions.Function function)
        {
            List <Parameter> retVal = new List <Parameter>();

            if (function != null)
            {
                foreach (Parameter formal in function.FormalParameters)
                {
                    Variables.IVariable actual = context.findOnStack(formal);
                    if (actual != null)
                    {
                        Values.PlaceHolder placeHolder = actual.Value as Values.PlaceHolder;
                        if (placeHolder != null)
                        {
                            retVal.Add(formal);
                        }
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Provides the changes performed by this statement
 /// </summary>
 /// <param name="context">The context on which the changes should be computed</param>
 /// <param name="changes">The list to fill with the changes</param>
 /// <param name="explanation">The explanatino to fill, if any</param>
 /// <param name="apply">Indicates that the changes should be applied immediately</param>
 public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply)
 {
     Variables.IVariable variable = ListExpression.GetVariable(context);
     if (variable != null)
     {
         // HacK : ensure that the value is a correct rigth side
         // and keep the result of the right side operation
         Values.ListValue listValue = variable.Value.RightSide(variable, false) as Values.ListValue;
         variable.Value = listValue;
         if (listValue != null)
         {
             int token = context.LocalScope.PushContext();
             context.LocalScope.setVariable(IteratorVariable);
             foreach (Values.IValue value in listValue.Val)
             {
                 if (value != EFSSystem.EmptyValue)
                 {
                     IteratorVariable.Value = value;
                     if (conditionSatisfied(context))
                     {
                         Call.GetChanges(context, changes, explanation, apply);
                     }
                 }
             }
             context.LocalScope.PopContext(token);
         }
         else
         {
             Root.AddError("List expression does not evaluate to a list value");
         }
     }
     else
     {
         Root.AddError("Cannot find variable for " + ListExpression.ToString());
     }
 }
Ejemplo n.º 26
0
        public override void visit(Generated.RuleCondition obj, bool subNodes)
        {
            Rules.RuleCondition ruleCondition = obj as Rules.RuleCondition;

            if (ruleCondition != null)
            {
                try
                {
                    bool found = false;
                    ruleCondition.Messages.Clear();

                    foreach (Rules.PreCondition preCondition in ruleCondition.PreConditions)
                    {
                        Interpreter.BinaryExpression expression = checkExpression(preCondition, preCondition.Expression) as Interpreter.BinaryExpression;
                        if (expression != null)
                        {
                            if (expression.IsSimpleEquality())
                            {
                                Types.ITypedElement variable = expression.Left.Ref as Types.ITypedElement;
                                if (variable != null)
                                {
                                    if (variable.Type != null)
                                    {
                                        // Check that when preconditions are based on a request,
                                        // the corresponding action affects the value Request.Disabled to the same variable
                                        if (variable.Type.Name.Equals("Request") && expression.Right != null && expression.Right is Interpreter.UnaryExpression)
                                        {
                                            Values.IValue val2 = expression.Right.Ref as Values.IValue;
                                            if (val2 != null && "Response".CompareTo(val2.Name) == 0)
                                            {
                                                if (ruleCondition != null)
                                                {
                                                    found = false;
                                                    foreach (Rules.Action action in ruleCondition.Actions)
                                                    {
                                                        Variables.IVariable var = OverallVariableFinder.INSTANCE.findByName(action, preCondition.findVariable());
                                                        Interpreter.Statement.VariableUpdateStatement update = action.Modifies(var);
                                                        if (update != null)
                                                        {
                                                            Interpreter.UnaryExpression updateExpr = update.Expression as Interpreter.UnaryExpression;
                                                            if (updateExpr != null)
                                                            {
                                                                Values.IValue val3 = updateExpr.Ref as Values.IValue;
                                                                if (val3 != null && val3.Name.CompareTo("Disabled") == 0)
                                                                {
                                                                    found = true;
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }

                                                    if (!found)
                                                    {
                                                        preCondition.AddError("Rules where the Pre conditions is based on a Request type variable must assign that variable the value 'Request.Disabled'");
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // Check that the outgoing variables are not read
                                    if (variable.Mode == Generated.acceptor.VariableModeEnumType.aOutgoing)
                                    {
                                        if (ruleCondition.Reads(variable))
                                        {
                                            preCondition.AddError("An outgoing variable cannot be read");
                                        }
                                    }

                                    // Check that the incoming variables are not modified
                                    if (variable.Mode == Generated.acceptor.VariableModeEnumType.aIncoming)
                                    {
                                        if (ruleCondition.Modifies(variable) != null)
                                        {
                                            preCondition.AddError("An incoming variable cannot be written");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    ruleCondition.AddException(exception);
                }
            }

            base.visit(obj, subNodes);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Fills the given structure with the values provided from the database
        /// </summary>
        /// <param name="aNameSpace">Namespace of the structure</param>
        /// <param name="fields">Fields to be copied into the structure</param>
        /// <param name="index">Index (of fields list) from which we have to start copying</param>
        /// <param name="aStructure">The structure to be filled</param>
        private void FillStructure(Types.NameSpace aNameSpace, ArrayList fields, ref int index, Values.StructureValue aStructure)
        {
            int j = 0;

            for (int i = index; i < fields.Count; i++)
            {
                Tests.DBElements.DBField field = fields[i] as Tests.DBElements.DBField;

                KeyValuePair <string, Variables.IVariable> pair = aStructure.SubVariables.ElementAt(j);
                Variables.IVariable variable = pair.Value;

                if (variable.Name.StartsWith(field.Variable))  // we use StartsWith and not Equals because we can have N_ITER_1 and N_ITER
                {
                    if (variable.Type is Types.Enum)
                    {
                        Types.Enum type = variable.Type as Types.Enum;
                        foreach (DataDictionary.Constants.EnumValue enumValue in type.Values)
                        {
                            int value = Int32.Parse(enumValue.getValue());
                            if (value == field.Value)
                            {
                                variable.Value = enumValue;
                                j++;
                                break;
                            }
                        }
                    }
                    else if (variable.Type is Types.Range)
                    {
                        Types.Range type = variable.Type as Types.Range;
                        variable.Value = new Values.IntValue(type, (decimal)field.Value);
                        j++;
                    }
                    else
                    {
                        throw new Exception("Unhandled variable type");
                    }
                    if (field.Variable.Equals("N_ITER")) // we have to create a sequence
                    {
                        KeyValuePair <string, Variables.IVariable> sequencePair = aStructure.SubVariables.ElementAt(j);
                        Variables.IVariable sequenceVariable = sequencePair.Value;
                        Types.Collection    collectionType   = (Types.Collection)EFSSystem.findType(aNameSpace, sequenceVariable.TypeName);
                        Values.ListValue    sequence         = new Values.ListValue(collectionType, new List <Values.IValue>());

                        for (int k = 0; k < field.Value; k++)
                        {
                            Types.Structure       structureType  = (Types.Structure)EFSSystem.findType(aNameSpace, sequence.CollectionType.Type.FullName);
                            Values.StructureValue structureValue = new Values.StructureValue(structureType, structureType.NameSpace);
                            FillStructure(aNameSpace, fields, ref index, structureValue);
                            sequence.Val.Add(structureValue);
                        }
                        sequenceVariable.Value = sequence;
                        j++;
                    }
                }

                // if all the fields of the structue are filled, we terminated
                if (j == aStructure.SubVariables.Count)
                {
                    index = i;
                    break;
                }
            }
        }
Ejemplo n.º 28
0
        private string format_eurobalise_message(DBElements.DBMessage message)
        {
            DataDictionary.Types.NameSpace nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Messages");
            Types.Structure       structureType      = (Types.Structure)EFSSystem.findType(nameSpace, "Messages.EUROBALISE.Message");
            Values.StructureValue structure          = new Values.StructureValue(structureType, nameSpace);

            int index = 0;

            FillStructure(nameSpace, message.Fields, ref index, structure); // fills the message fields


            // then we fill the packets
            KeyValuePair <string, Variables.IVariable> subSequencePair = structure.SubVariables.ElementAt(structure.SubVariables.Count - 1);

            Variables.IVariable subSequenceVariable = subSequencePair.Value;

            Types.Collection collectionType = (Types.Collection)EFSSystem.findType(nameSpace, "Messages.EUROBALISE.Collection1");
            Values.ListValue collection     = new Values.ListValue(collectionType, new List <Values.IValue>());

            Types.Structure       subStructure1Type = (Types.Structure)EFSSystem.findType(nameSpace, "Messages.EUROBALISE.SubStructure1");
            Values.StructureValue subStructure1     = new Values.StructureValue(subStructure1Type, nameSpace);

            Types.Structure       packetStructure = (Types.Structure)EFSSystem.findType(nameSpace, "Messages.PACKET.TRACK_TO_TRAIN.Message");
            Values.StructureValue packetValue     = new Values.StructureValue(packetStructure, nameSpace);

            // will contain the list of all packets of the message and then be added to the structure packetValue
            ArrayList subStructures = new ArrayList();

            foreach (DBElements.DBPacket packet in message.Packets)
            {
                Tests.DBElements.DBField nidPacketField = packet.Fields[0] as Tests.DBElements.DBField;

                if (nidPacketField.Value != 255)  // 255 means "end of information"
                {
                    Values.StructureValue subStructure = FindStructure(nidPacketField.Value);

                    index = 0;
                    FillStructure(nameSpace, packet.Fields, ref index, subStructure);

                    subStructures.Add(subStructure);
                }
            }

            // the collection of the message packets is copied to the structure packetValue
            int i = 0;

            foreach (KeyValuePair <string, Variables.IVariable> pair in packetValue.SubVariables)
            {
                if (i == subStructures.Count)
                {
                    break;
                }
                string variableName = pair.Key;
                Values.StructureValue structureValue = subStructures[i] as Values.StructureValue;
                if (structureValue.Structure.FullName.Contains(variableName))
                {
                    Variables.IVariable variable = pair.Value;
                    variable.Value = structureValue;
                    i++;
                }
            }

            subStructure1.SubVariables.ElementAt(0).Value.Value = packetValue;
            collection.Val.Add(subStructure1);
            subSequenceVariable.Value = collection;

            return(structure.Name);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Provides the changes performed by this statement
        /// </summary>
        /// <param name="context">The context on which the changes should be computed</param>
        /// <param name="changes">The list to fill with the changes</param>
        /// <param name="explanation">The explanatino to fill, if any</param>
        /// <param name="apply">Indicates that the changes should be applied immediately</param>
        public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply)
        {
            Variables.IVariable variable = ListExpression.GetVariable(context);
            if (variable != null)
            {
                // HacK : ensure that the value is a correct rigth side
                // and keep the result of the right side operation
                Values.ListValue listValue = variable.Value.RightSide(variable, false) as Values.ListValue;
                variable.Value = listValue;
                if (listValue != null)
                {
                    Values.IValue value = Value.GetValue(context);
                    if (value != null)
                    {
                        Values.ListValue newListValue = new Values.ListValue(listValue);
                        int index = newListValue.Val.IndexOf(EFSSystem.EmptyValue);
                        if (index >= 0)
                        {
                            newListValue.Val[index] = value;
                        }
                        else
                        {
                            // List is full, try to remove an element before inserting the new element
                            if (ReplaceElement != null)
                            {
                                Values.IValue removeValue = ReplaceElement.GetValue(context);
                                index = newListValue.Val.IndexOf(removeValue);
                                if (index >= 0)
                                {
                                    newListValue.Val[index] = value;
                                }
                                else
                                {
                                    Root.AddError("Cannot remove replacing element " + removeValue.Name);
                                }
                            }
                            else
                            {
                                Root.AddError("Cannot add new element in list value : list is full");
                            }
                        }

                        Rules.Change change = new Rules.Change(variable, variable.Value, newListValue);
                        changes.Add(change, apply);
                        explanation.SubExplanations.Add(new ExplanationPart(Root, change));
                    }
                    else
                    {
                        Root.AddError("Cannot find value for " + Value.ToString());
                    }
                }
                else
                {
                    Root.AddError("Variable " + ListExpression.ToString() + " does not contain a list value");
                }
            }
            else
            {
                Root.AddError("Cannot find variable for " + ListExpression.ToString());
            }
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Indicates whether this rule uses the typed element
 /// </summary>
 /// <param name="variable"></param>
 /// <returns></returns>
 public bool Uses(Variables.IVariable variable)
 {
     return(Modifies(variable) != null || Reads(variable));
 }