/// <summary>
        /// Provides the value associated to this Expression
        /// </summary>
        /// <param name="instance">The instance on which the value is computed</param>
        /// <param name="localScope">The local scope used to compute the value of this expression</param>
        /// <param name="globalFind">Indicates that the search should be performed globally</param>
        /// <returns></returns>
        public override Values.IValue GetValue(InterpretationContext context)
        {
            Values.StructureValue retVal = null;

            Types.Structure structureType = Structure.GetExpressionType() as Types.Structure;
            if (structureType != null)
            {
                retVal = new Values.StructureValue(structureType, Root);

                foreach (KeyValuePair <string, Expression> pair in Associations)
                {
                    Values.IValue      val = pair.Value.GetValue(new InterpretationContext(context));
                    Variables.Variable var = (Variables.Variable)Generated.acceptor.getFactory().createVariable();
                    var.Name      = pair.Key;
                    var.Value     = val;
                    var.Enclosing = retVal;
                    retVal.set(var);
                }
            }
            else
            {
                AddError("Cannot determine structure type for " + ToString());
            }

            return(retVal);
        }
Esempio n. 2
0
        /// <summary>
        /// Evaluates the rules associated to a single variable
        /// </summary>
        /// <param name="priority"></param>
        /// <param name="activations"></param>
        /// <param name="variable"></param>
        private void EvaluateVariable(Generated.acceptor.RulePriority priority, HashSet <Activation> activations, Variables.IVariable variable)
        {
            if (variable != null)
            {
                if (variable.Type is Types.Structure)
                {
                    List <Rules.RuleCondition> rules     = new List <RuleCondition>();
                    Types.Structure            structure = variable.Type as Types.Structure;
                    foreach (Rule rule in structure.Rules)
                    {
                        rule.Evaluate(this, priority, variable, rules);
                    }
                    Activation.RegisterRules(activations, rules, variable);

                    StructureValue value = variable.Value as StructureValue;
                    if (value != null)
                    {
                        foreach (Variables.IVariable subVariable in value.SubVariables.Values)
                        {
                            EvaluateVariable(priority, activations, subVariable);
                        }
                    }
                }
                else if (variable.Type is Types.StateMachine)
                {
                    List <Rules.RuleCondition> rules = new List <RuleCondition>();
                    EvaluateStateMachine(rules, priority, variable);
                    Activation.RegisterRules(activations, rules, variable);
                }
                else if (variable.Type is Types.Collection)
                {
                    Types.Collection collectionType = variable.Type as Types.Collection;
                    if (variable.Value != EFSSystem.EmptyValue)
                    {
                        ListValue val = variable.Value as ListValue;

                        int i = 1;
                        foreach (IValue subVal in val.Val)
                        {
                            Variables.Variable tmp = new Variables.Variable();
                            tmp.Name  = variable.Name + '[' + i + ']';
                            tmp.Type  = collectionType.Type;
                            tmp.Value = subVal;
                            EvaluateVariable(priority, activations, tmp);
                            i = i + 1;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Coputes targets from the function and adds them to the collection
        /// </summary>
        /// <param name="function">Function containing targets</param>
        /// <param name="collection">Collection to be filled with targets</param>
        private void ComputeTargets(Function function, Values.ListValue collection)
        {
            if (function != null)
            {
                Graph graph = function.Graph;
                if (graph != null && graph.Segments.Count > 1)
                {
                    double prevSpeed = Double.MaxValue;
                    for (int i = 1; i < graph.Segments.Count; i++)
                    {
                        Graph.Segment         s             = graph.Segments[i];
                        Types.Structure       structureType = (Types.Structure)EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Kernel.SpeedAndDistanceMonitoring.TargetSupervision"), "Kernel.SpeedAndDistanceMonitoring.TargetSupervision.Target");
                        Values.StructureValue value         = new Values.StructureValue(structureType, structureType.NameSpace);

                        Variables.Variable speed = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable();
                        speed.Type      = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Speed");
                        speed.Name      = "Speed";
                        speed.Mode      = Generated.acceptor.VariableModeEnumType.aInternal;
                        speed.Default   = "0.0";
                        speed.Enclosing = value;
                        speed.Value     = new Values.DoubleValue(EFSSystem.DoubleType, s.Val(s.Start));
                        value.set(speed);

                        Variables.Variable location = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable();
                        location.Type      = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Distance");
                        location.Name      = "Location";
                        location.Mode      = Generated.acceptor.VariableModeEnumType.aInternal;
                        location.Default   = "0.0";
                        location.Enclosing = value;
                        location.Value     = new Values.DoubleValue(EFSSystem.DoubleType, s.Start);
                        value.set(location);

                        Variables.Variable length = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable();
                        length.Type      = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Length");
                        length.Name      = "Length";
                        length.Mode      = Generated.acceptor.VariableModeEnumType.aInternal;
                        length.Default   = "0.0";
                        length.Enclosing = value;
                        length.Value     = new Values.DoubleValue(EFSSystem.DoubleType, s.End);
                        value.set(length);

                        if (s.Val(s.Start) < prevSpeed)
                        {
                            collection.Val.Add(value);
                        }
                        prevSpeed = s.Val(s.Start);
                    }
                }
            }
        }
        /// <summary>
        /// Checks the expression and appends errors to the root tree node when inconsistencies are found
        /// </summary>
        public override void checkExpression()
        {
            Types.Structure structureType = Structure.GetExpressionType() as Types.Structure;
            if (structureType != null)
            {
                foreach (KeyValuePair <string, Expression> pair in Associations)
                {
                    string     name       = pair.Key;
                    Expression expression = pair.Value;

                    List <Utils.INamable> targets = new List <Utils.INamable>();
                    structureType.Find(name, targets);
                    if (targets.Count > 0)
                    {
                        expression.checkExpression();
                        Types.Type type = expression.GetExpressionType();
                        if (type != null)
                        {
                            foreach (Utils.INamable namable in targets)
                            {
                                Types.ITypedElement element = namable as Types.ITypedElement;
                                if (element != null && element.Type != null)
                                {
                                    if (!element.Type.Match(type))
                                    {
                                        AddError("Expression " + expression.ToString() + " type (" + type.FullName + ") does not match the target element " + element.Name + " type (" + element.Type.FullName + ")");
                                    }
                                }
                            }
                        }
                        else
                        {
                            AddError("Expression " + expression.ToString() + " type cannot be found");
                        }
                    }
                    else
                    {
                        Root.AddError("Cannot find " + name + " in structure " + Structure.ToString());
                    }
                }
            }
            else
            {
                AddError("Cannot find structure type " + Structure.ToString());
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Finds the type of the structure corresponding to the provided NID_PACKET
        /// </summary>
        /// <param name="nameSpace">The namespace where the type has to be found</param>
        /// <param name="nidPacket">The id of the packet</param>
        /// <returns></returns>
        private Values.StructureValue FindStructure(int nidPacket)
        {
            Types.Structure structure = null;
            DataDictionary.Types.NameSpace nameSpace;

            if (nidPacket != 44)
            {
                nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Messages.PACKET.TRACK_TO_TRAIN");
                foreach (DataDictionary.Types.NameSpace subNameSpace in nameSpace.SubNameSpaces)
                {
                    Types.Structure       structureType  = (Types.Structure)EFSSystem.findType(subNameSpace, subNameSpace.FullName + ".Message");
                    Values.StructureValue structureValue = new Values.StructureValue(structureType, nameSpace);

                    foreach (KeyValuePair <string, Variables.IVariable> pair in structureValue.SubVariables)
                    {
                        string variableName = pair.Key;
                        if (variableName.Equals("NID_PACKET"))
                        {
                            Values.IntValue value = pair.Value.Value as Values.IntValue;
                            if (value.Val == nidPacket)
                            {
                                structure = structureType;
                            }
                        }
                        if (structure != null)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Messages.PACKET.DATA_USED_BY_APPLICATIONS_OUTSIDE_THE_ERTMS_ETCS_SYSTEM");
                structure = (Types.Structure)EFSSystem.findType(nameSpace, nameSpace.FullName + ".Message");
            }

            Values.StructureValue retVal = null;
            if (structure != null)
            {
                retVal = new Values.StructureValue(structure, nameSpace);
            }

            return(retVal);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="structure"></param>
        public StructureValue(Types.Structure structure, Utils.INamable enclosing)
            : base(structure, new Dictionary <string, Utils.INamable>())
        {
            Enclosing = structure;

            foreach (Types.StructureElement element in Structure.Elements)
            {
                Variables.Variable variable = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable();
                if (element.Type != null)
                {
                    variable.Type = element.Type;
                }
                variable.Name      = element.Name;
                variable.Mode      = element.Mode;
                variable.Default   = element.Default;
                variable.Enclosing = enclosing;
                variable.Enclosing = this;
                set(variable);
            }
        }
Esempio n. 7
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;
                }
            }
        }
Esempio n. 8
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);
        }