Наследование: Generated.Collection, ITypedElement
Пример #1
0
        /// <summary>
        ///     Checks the statement for semantical errors
        /// </summary>
        public override void CheckStatement()
        {
            if (ListExpression != null)
            {
                ListExpression.CheckExpression();
                Collection listExpressionType = ListExpression.GetExpressionType() as Collection;
                if (listExpressionType == null)
                {
                    Root.AddError("Target does not references a list");
                }
            }
            else
            {
                Root.AddError("List should be specified");
            }

            if (ConditionExpression != null)
            {
                ConditionExpression.CheckExpression();
            }

            if (AppliedStatement != null)
            {
                AppliedStatement.CheckStatement();
            }
            else
            {
                Root.AddError("Procedure should be specified in the APPLY statement");
            }
        }
Пример #2
0
        public void TestRefactorStructureName()
        {
            Dictionary test       = CreateDictionary("Test");
            NameSpace  n1         = CreateNameSpace(test, "N1");
            Collection collection = CreateCollection(n1, "Col", "Integer", 10);
            Variable   v          = CreateVariable(n1, "V", "Col");

            v.setDefaultValue("[]");
            RuleCondition rc1 = CreateRuleAndCondition(n1, "Rule1");
            Action        a1  = CreateAction(rc1, "INSERT 1 IN V");
            RuleCondition rc2 = CreateRuleAndCondition(n1, "Rule2");
            Action        a2  = CreateAction(rc2, "INSERT 2 IN V");

            // ReSharper disable once UseObjectOrCollectionInitializer
            Runner runner = new Runner(false);

            runner.CheckForCompatibleChanges = true;
            runner.Cycle();

            ListValue listValue = v.Value as ListValue;

            Assert.IsNotNull(listValue);
            Assert.AreEqual(2, listValue.Val.Count);
            Assert.AreEqual(0, a1.Messages.Count);
            Assert.AreEqual(0, a2.Messages.Count);
        }
Пример #3
0
        /// <summary>
        ///     Checks the statement for semantical errors
        /// </summary>
        public override void CheckStatement()
        {
            if (ListExpression != null)
            {
                if (ListExpression.Ref is Parameter)
                {
                    Root.AddError("Cannot change the list value which is a parameter (" + ListExpression + ")");
                }

                Collection targetListType = ListExpression.GetExpressionType() as Collection;
                if (targetListType != null)
                {
                    if (Condition != null)
                    {
                        Condition.CheckExpression();
                        BoolType conditionType = Condition.GetExpressionType() as BoolType;
                        if (conditionType == null)
                        {
                            Root.AddError("Condition does not evaluates to boolean");
                        }
                    }
                }
                else
                {
                    Root.AddError("Cannot determine type of " + ListExpression);
                }
            }
            else
            {
                Root.AddError("List should be specified");
            }
        }
Пример #4
0
        /// <summary>
        ///     Performs the semantic analysis of the statement
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(INamable instance = null)
        {
            bool retVal = base.SemanticAnalysis(instance);

            if (retVal)
            {
                // ListExpression
                if (ListExpression != null)
                {
                    ListExpression.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(ListExpression.StaticUsage, Usage.ModeEnum.ReadAndWrite);

                    Collection collectionType = ListExpression.GetExpressionType() as Collection;
                    if (collectionType != null)
                    {
                        IteratorVariable.Type = collectionType.Type;
                    }
                }
                else
                {
                    AddError("List expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }

                // Condition
                if (Condition != null)
                {
                    Condition.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(Condition.StaticUsage, Usage.ModeEnum.Read);
                }
            }

            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>
        /// <param name="runner"></param>
        public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation,
                                        bool apply, Runner runner)
        {
            IVariable var = VariableIdentification.GetVariable(context);

            if (var != null)
            {
                IValue value = Expression.GetExpressionValue(context, explanation);
                if (value != null)
                {
                    value = value.RightSide(var, true, true);
                }

                Range      range      = var.Type as Range;
                Collection collection = var.Type as Collection;
                if (range != null && range.convert(value) == null)
                {
                    AddError("Value " + value + " is outside range", RuleChecksEnum.ExecutionFailed);
                }
                else if (collection != null && collection.convert(value) == null)
                {
                    AddError("Value " + value + " cannot be assigned to variable", RuleChecksEnum.ExecutionFailed);
                }
                else
                {
                    Change change = new Change(var, var.Value, value);
                    changes.Add(change, apply, runner);
                    ExplanationPart.CreateSubExplanation(explanation, Root, change);
                }
            }
            else
            {
                AddError("Cannot find variable " + VariableIdentification, RuleChecksEnum.ExecutionFailed);
            }
        }
Пример #6
0
        public override Collection createCollection()
        {
            Collection retVal = new Types.Collection();

            _defaultValueSetter.SetDefaultValue(retVal);

            return(retVal);
        }
Пример #7
0
        /// <summary>
        ///     Checks the statement for semantical errors
        /// </summary>
        public override void CheckStatement()
        {
            if (ListExpression != null)
            {
                if (ListExpression.Ref is Parameter)
                {
                    Root.AddError("Cannot change the list value which is a parameter (" + ListExpression + ")");
                }

                Collection targetListType = ListExpression.GetExpressionType() as Collection;
                if (targetListType != null)
                {
                    Type elementType = Value.GetExpressionType();
                    if (elementType != targetListType.Type)
                    {
                        Root.AddError("Inserted element type does not corresponds to list type");
                    }

                    if (Condition != null)
                    {
                        Condition.CheckExpression();
                        BoolType conditionType = Condition.GetExpressionType() as BoolType;
                        if (conditionType == null)
                        {
                            Root.AddError("Condition does not evaluates to boolean");
                        }
                    }
                    else
                    {
                        Root.AddError("Condition should be provided");
                    }
                }
                else
                {
                    Root.AddError("Cannot determine collection type of " + ListExpression);
                }
            }
            else
            {
                Root.AddError("List should be specified");
            }

            if (Value != null)
            {
                Value.CheckExpression();
            }
            else
            {
                Root.AddError("Value should be specified");
            }
        }
Пример #8
0
        /// <summary>
        ///     Performs the semantic analysis of the expression
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <param name="expectation">Indicates the kind of element we are looking for</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(INamable instance, BaseFilter expectation)
        {
            bool retVal = base.SemanticAnalysis(instance, expectation);

            if (retVal)
            {
                Type elementType = null;

                if (ListElements != null)
                {
                    foreach (Expression expr in ListElements)
                    {
                        expr.SemanticAnalysis(instance, expectation);
                        StaticUsage.AddUsages(expr.StaticUsage, null);

                        Type current = expr.GetExpressionType();
                        if (elementType == null)
                        {
                            elementType = current;
                        }
                        else
                        {
                            if (!current.Match(elementType))
                            {
                                AddError("Cannot mix types " + current + " and " + elementType + "in collection", RuleChecksEnum.SemanticAnalysisError);
                            }
                        }
                    }
                }

                if (elementType != null)
                {
                    ExpressionType           = (Collection)acceptor.getFactory().createCollection();
                    ExpressionType.Type      = elementType;
                    ExpressionType.Name      = "ListOf_" + elementType.FullName;
                    ExpressionType.Enclosing = Root.EFSSystem;
                    ExpressionType.setMaxSize(ListElements.Count);

                    StaticUsage.AddUsage(elementType, Root, Usage.ModeEnum.Type);
                }
                else
                {
                    ExpressionType = new GenericCollection(EfsSystem.Instance);
                }
            }

            return(retVal);
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="panel"></param>
 /// <param name="model"></param>
 public CollectionModelControl(ModelDiagramPanel panel, Collection model)
     : base(panel, model)
 {
 }
Пример #10
0
        public override Collection createCollection()
        {
            Collection retVal = new Types.Collection();

            _defaultValueSetter.SetDefaultValue(retVal);

            return retVal;
        }
Пример #11
0
        /// <summary>
        ///     Performs the semantic analysis of the statement
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(INamable instance = null)
        {
            bool retVal = base.SemanticAnalysis(instance);

            if (retVal)
            {
                // ListExpression
                Collection collectionType = null;
                if (ListExpression != null)
                {
                    ListExpression.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(ListExpression.StaticUsage, Usage.ModeEnum.ReadAndWrite);

                    collectionType = ListExpression.GetExpressionType() as Collection;
                    if (collectionType != null)
                    {
                        IteratorVariable.Type = collectionType.Type;
                    }
                    else
                    {
                        AddError("Cannot determine collection type", RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    AddError("List expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }

                // Value
                if (Value != null)
                {
                    Value.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(Value.StaticUsage, Usage.ModeEnum.Read);
                    Type valueType = Value.GetExpressionType();
                    if (valueType != null)
                    {
                        if (collectionType != null && !valueType.Match(collectionType.Type))
                        {
                            AddError("Type of " + Value + " does not match collection type " + collectionType, RuleChecksEnum.SemanticAnalysisError);
                        }
                    }
                    else
                    {
                        AddError("Cannot determine type of " + Value, RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    AddError("Replacement value not provided", RuleChecksEnum.SemanticAnalysisError);
                }

                // Condition
                if (Condition != null)
                {
                    Condition.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(Condition.StaticUsage, Usage.ModeEnum.Read);
                }
            }

            return(retVal);
        }
Пример #12
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 static void FillStructure(NameSpace aNameSpace, ArrayList fields, ref int currentIndex,
                                          StructureValue aStructure)
        {
            EfsSystem system = EfsSystem.Instance;

            int j = 0;

            while (currentIndex < fields.Count)
            {
                DBField field = fields[currentIndex] as DBField;

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

                // conditional variables can be missing in the database fields, but present in our structure => skip them
                while (!variable.Name.StartsWith(field.Variable) && j < aStructure.SubVariables.Count - 1)
                {
                    j++;
                    pair     = aStructure.SubVariables.ElementAt(j);
                    variable = pair.Value;
                }

                // We use StartsWith and not Equals because we can have N_ITER_1 and N_ITER
                if (variable.Name.StartsWith(field.Variable))
                {
                    if (variable.Type is Enum)
                    {
                        Enum type = variable.Type as Enum;
                        foreach (EnumValue enumValue in type.Values)
                        {
                            int value = int.Parse(enumValue.getValue());
                            int other = int.Parse(field.Value);
                            if (value == other)
                            {
                                variable.Value = enumValue;
                                j++;
                                break;
                            }
                        }
                    }
                    else if (variable.Type is Range)
                    {
                        Range  type = variable.Type as Range;
                        object v    = VariableConverter.INSTANCE.Convert(variable.Name, field.Value);

                        string stringValue = v as string;
                        if (stringValue != null)
                        {
                            int intValue;
                            if (int.TryParse(stringValue, out intValue))
                            {
                                v = intValue;
                            }
                        }
                        variable.Value = new IntValue(type, (int)v);
                        j++;
                    }
                    else if (variable.Type is StringType)
                    {
                        StringType type = variable.Type as StringType;
                        variable.Value = new StringValue(type, field.Value);
                        j++;
                    }
                    else
                    {
                        throw new Exception("Unhandled variable type");
                    }

                    if (variable.Name.StartsWith("N_ITER")) // we have to create a sequence
                    {
                        KeyValuePair <string, IVariable> sequencePair = aStructure.SubVariables.ElementAt(j);
                        IVariable  sequenceVariable = sequencePair.Value;
                        Collection collectionType   = (Collection)system.FindType(aNameSpace, sequenceVariable.TypeName);
                        ListValue  sequence         = new ListValue(collectionType, new List <IValue>());

                        int value = int.Parse(field.Value);
                        for (int k = 0; k < value; k++)
                        {
                            currentIndex++;
                            Structure structureType =
                                (Structure)system.FindType(aNameSpace, sequence.CollectionType.Type.FullName);
                            StructureValue structureValue = new StructureValue(structureType);
                            FillStructure(aNameSpace, fields, ref currentIndex, structureValue);
                            sequence.Val.Add(structureValue);
                        }
                        sequenceVariable.Value = sequence;
                        j++;
                    }
                }

                // Special case for X_TEXT
                if ("Sequence1".Equals(variable.Name) && "X_TEXT".Equals(field.Variable))
                {
                    KeyValuePair <string, IVariable> sequencePair = aStructure.SubVariables.ElementAt(j);
                    IVariable  sequenceVariable = sequencePair.Value;
                    Collection collectionType   = (Collection)system.FindType(aNameSpace, sequenceVariable.TypeName);
                    ListValue  sequence         = new ListValue(collectionType, new List <IValue>());
                    while (field != null && "X_TEXT".Equals(field.Variable))
                    {
                        if (string.IsNullOrEmpty(field.Value))
                        {
                            field.Value = " ";
                        }
                        Structure structureType =
                            (Structure)system.FindType(aNameSpace, sequence.CollectionType.Type.FullName);
                        StructureValue structureValue = new StructureValue(structureType);
                        FillStructure(aNameSpace, fields, ref currentIndex, structureValue);
                        sequence.Val.Add(structureValue);
                        currentIndex += 1;
                        if (currentIndex < fields.Count)
                        {
                            field = fields[currentIndex] as DBField;
                        }
                        else
                        {
                            field = null;
                        }
                    }
                    sequenceVariable.Value = sequence;
                    j++;
                }

                // if all the fields of the structue are filled, we terminated
                if (j == aStructure.SubVariables.Count)
                {
                    break;
                }
                else
                {
                    currentIndex += 1;
                }
            }
        }
Пример #13
0
        private static ListValue get_message_packets(DBMessage message, NameSpace nameSpace, EfsSystem system)
        {
            ListValue retVal;

            Collection collectionType    = (Collection)system.FindType(nameSpace, "Collection1");
            Structure  subStructure1Type = (Structure)system.FindType(nameSpace, "SubStructure1");

            string packetLocation = "Messages.PACKET.";

            if (nameSpace.FullName.Contains("TRAIN_TO_TRACK"))
            {
                packetLocation += "TRAIN_TO_TRACK.Message";
            }
            else
            {
                packetLocation += "TRACK_TO_TRAIN.Message";
            }

            Structure packetStructureType = (Structure)system.FindType(nameSpace, packetLocation);

            retVal = new ListValue(collectionType, new List <IValue>());

            foreach (DBPacket packet in message.Packets)
            {
                DBField nidPacketField = packet.Fields[0] as DBField;
                if (nidPacketField.Value != "255") // 255 means "end of information"
                {
                    int            packetId     = int.Parse(nidPacketField.Value);
                    StructureValue subStructure = FindStructure(packetId);

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

                    StructureValue subStructure1 = new StructureValue(subStructure1Type);

                    // For Balise messages, we have an extra level of information to fill, so here we define StructureVal in one of two ways
                    StructureValue structureVal;
                    if (subStructure1.SubVariables.Count == 1 &&
                        subStructure1.SubVariables.ContainsKey("TRACK_TO_TRAIN"))
                    {
                        // For a Balise message, we have an extra level of structures for TRACK_TO_TRAIN
                        structureVal = new StructureValue(packetStructureType);

                        subStructure1.SubVariables["TRACK_TO_TRAIN"].Value = structureVal;
                    }
                    else
                    {
                        // For RBC, the collection directly holds the different packet types
                        structureVal = subStructure1;
                    }

                    // Find the right variable in the packet to add the structure we just created
                    foreach (KeyValuePair <string, IVariable> pair in structureVal.SubVariables)
                    {
                        string variableName = pair.Key;
                        if (subStructure.Structure.FullName.Contains(variableName))
                        {
                            pair.Value.Value = subStructure;

                            retVal.Val.Add(subStructure1);

                            break;
                        }
                    }
                }
            }

            return(retVal);
        }
        /// <summary>
        ///     Performs the semantic analysis of the expression
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <param name="expectation">Indicates the kind of element we are looking for</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(INamable instance, BaseFilter expectation)
        {
            bool retVal = base.SemanticAnalysis(instance, expectation);

            if (retVal)
            {
                Type elementType = null;

                if (ListElements != null)
                {
                    foreach (Expression expr in ListElements)
                    {
                        expr.SemanticAnalysis(instance, expectation);
                        StaticUsage.AddUsages(expr.StaticUsage, null);

                        Type current = expr.GetExpressionType();
                        if (elementType == null)
                        {
                            elementType = current;
                        }
                        else
                        {
                            if (!current.Match(elementType))
                            {
                                AddError("Cannot mix types " + current + " and " + elementType + "in collection");
                            }
                        }
                    }
                }

                if (elementType != null)
                {
                    ExpressionType = (Collection) acceptor.getFactory().createCollection();
                    ExpressionType.Type = elementType;
                    ExpressionType.Name = "ListOf_" + elementType.FullName;
                    ExpressionType.Enclosing = Root.EFSSystem;
                    ExpressionType.setMaxSize(ListElements.Count);

                    StaticUsage.AddUsage(elementType, Root, Usage.ModeEnum.Type);
                }
                else
                {
                    ExpressionType = new GenericCollection(EfsSystem.Instance);
                }
            }

            return retVal;
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="source"></param>
 /// <param name="target"></param>
 /// <param name="model"></param>
 public CollectionTypeArrow(Collection source, Type target, Collection model)
     : base(source, target, "of " + source.getMaxSize(), model)
 {
 }