Пример #1
0
            private void displayType(int indent, Type type)
            {
                Structure structureType = type as Structure;

                if (structureType != null)
                {
                    foreach (StructureElement element in structureType.Elements)
                    {
                        displayIndent(indent);
                        Type subType = element.Type;
                        Writer.WriteLine(element.Name + " : " + subType.FullName);
                        displayType(indent + 1, subType);
                    }
                }

                Range rangeType = type as Range;

                if (rangeType != null)
                {
                    displayIndent(indent);
                    Writer.WriteLine("RANGE " + rangeType.MinValueAsDouble + ".." + rangeType.MaxValueAsDouble +
                                     " DEFAULT VALUE = " + rangeType.DefaultValue.LiteralName);
                }

                Collection collectionType = type as Collection;

                if (collectionType != null)
                {
                    displayIndent(indent);
                    Type subType = collectionType.Type;
                    Writer.WriteLine("COLLECTION [" + collectionType.getMaxSize() + "] OF " + subType.FullName);
                    displayType(indent + 1, subType);
                }
            }
Пример #2
0
        /// <summary>
        ///     Provides the value of the function
        /// </summary>
        /// <param name="context"></param>
        /// <param name="actuals">the actual parameters values</param>
        /// <param name="explain"></param>
        /// <returns>The value for the function application</returns>
        public override IValue Evaluate(InterpretationContext context, Dictionary <Actual, IValue> actuals,
                                        ExplanationPart explain)
        {
            IValue retVal = null;

            int token = context.LocalScope.PushContext();

            AssignParameters(context, actuals);

            ListValue value = context.FindOnStack(Collection) as ListValue;

            if (value != null)
            {
                Collection collectionType = value.Type as Collection;
                if (collectionType != null && collectionType.Type != null)
                {
                    Type elementType = collectionType.Type;

                    if (value.Val.Count >= collectionType.getMaxSize())
                    {
                        AddError("Cannot allocate element in list : list full");
                    }
                    else
                    {
                        retVal = elementType.DefaultValue;
                        value.Val.Add(retVal);
                    }
                }
            }
            context.LocalScope.PopContext(token);

            return(retVal);
        }
Пример #3
0
        /// <summary>
        ///     Converts the value provided as an EFS value
        /// </summary>
        /// <returns></returns>
        public override IValue ConvertBack(Type type)
        {
            IValue retVal = type.getValue(Image);

            CheckReturnValue(retVal, type);
            return(retVal);
        }
Пример #4
0
            private void displayVariable(Variable var)
            {
                switch (var.Mode)
                {
                case acceptor.VariableModeEnumType.aIncoming:
                    Writer.Write("IN     ");
                    break;

                case acceptor.VariableModeEnumType.aInOut:
                    Writer.Write("IN OUT ");
                    break;

                case acceptor.VariableModeEnumType.aOutgoing:
                    Writer.Write("   OUT ");
                    break;

                default:
                    return;
                }

                Type type = var.Type;

                Writer.WriteLine(var.FullName + " : " + type.FullName);

                displayType(1, type);
            }
Пример #5
0
        /// <summary>
        ///     Provides the type of this expression
        /// </summary>
        /// <returns></returns>
        public override Type GetExpressionType()
        {
            Type retVal = null;

            Type iteratorType = IteratorExpression.GetExpressionType();

            if (iteratorType != null)
            {
                Collection collection = (Collection)acceptor.getFactory().createCollection();
                collection.Enclosing = EfsSystem.Instance;
                collection.Type      = iteratorType;
                Collection originalListType = ListExpression.GetExpressionType() as Collection;
                if (originalListType != null)
                {
                    collection.setMaxSize(originalListType.getMaxSize());
                }

                retVal = collection;
            }
            else
            {
                AddError("Cannot evaluate iterator type for " + ToString(), RuleChecksEnum.SemanticAnalysisError);
            }

            return(retVal);
        }
Пример #6
0
        /// <summary>
        ///     Converts the value provided as an EFS value
        /// </summary>
        /// <returns></returns>
        public override IValue ConvertBack(Type type)
        {
            DataDictionary.Values.StructureValue retVal = null;

            Structure structureType = type as Structure;

            if (structureType != null)
            {
                retVal = new DataDictionary.Values.StructureValue(structureType);

                foreach (KeyValuePair <string, Value> pair in Value)
                {
                    if (pair.Value != null)
                    {
                        StructureElement element = structureType.FindStructureElement(pair.Key);
                        if (element != null)
                        {
                            Field field = retVal.CreateField(element, structureType);
                            field.Value = pair.Value.ConvertBack(element.Type);
                        }
                        else
                        {
                            throw new FaultException <EFSServiceFault>(
                                      new EFSServiceFault("Cannot find element named " + pair.Key + " in structure " +
                                                          structureType.FullName));
                        }
                    }
                }
            }

            CheckReturnValue(retVal, type);
            return(retVal);
        }
Пример #7
0
        /// <summary>
        ///     Converts the value provided as an EFS value
        /// </summary>
        /// <returns></returns>
        public override IValue ConvertBack(Type type)
        {
            IValue retVal = type.getValue(Image);

            CheckReturnValue(retVal, type);
            return retVal;
        }
Пример #8
0
        /// <summary>
        ///     Checks the expression and appends errors to the root tree node when inconsistencies are found
        /// </summary>
        public override void CheckExpression()
        {
            base.CheckExpression();

            Type initialValueType = InitialValue.GetExpressionType();

            if (initialValueType != null)
            {
                Collection listExpressionType = ListExpression.GetExpressionType() as Collection;
                if (listExpressionType != null)
                {
                    IteratorExpression.CheckExpression();
                }
            }
            else
            {
                AddError("Cannot determine initial value expression type for " + ToString(), RuleChecksEnum.SemanticAnalysisError);
            }


            bool refToResultFound = false;

            foreach (Usage usage in IteratorExpression.StaticUsage.AllUsages)
            {
                if (usage.Referenced == AccumulatorVariable && usage.Mode == Usage.ModeEnum.Read)
                {
                    refToResultFound = true;
                    break;
                }
            }
            if (!refToResultFound)
            {
                AddError("REDUCE expressions should reference RESULT variable", RuleChecksEnum.SyntaxError);
            }
        }
Пример #9
0
        protected override void BuildModel()
        {
            Nodes.Clear();

            if (false)
            {
                // This takes too much time. Do not do, for now.
                if (Root is DataDictionary.Types.ITypedElement)
                {
                    DataDictionary.Variables.IVariable variable = Root as DataDictionary.Variables.IVariable;
                    foreach (DataDictionary.Rules.RuleCondition ruleCondition in DataDictionary.Rules.Rule.RulesUsingThisElement(variable))
                    {
                        Nodes.Add(new RuleUsageTreeNode(ruleCondition));
                    }
                }
                else if (Root is DataDictionary.Types.Type)
                {
                    DataDictionary.Types.Type type = Root as DataDictionary.Types.Type;
                    foreach (DataDictionary.Types.ITypedElement element in DataDictionary.Types.Type.ElementsOfType(type))
                    {
                        Nodes.Add(new TypeUsageTreeNode(element));
                    }
                }
            }
        }
Пример #10
0
        /// <summary>
        ///     Converts the value provided as an EFS value
        /// </summary>
        /// <returns></returns>
        public override IValue ConvertBack(Type type)
        {
            DataDictionary.Values.StructureValue retVal = null;

            Structure structureType = type as Structure;
            if (structureType != null)
            {
                retVal = new DataDictionary.Values.StructureValue(structureType);

                foreach (KeyValuePair<string, Value> pair in Value)
                {
                    StructureElement element = structureType.FindStructureElement(pair.Key);
                    if (element != null)
                    {
                        Variable variable = (Variable) acceptor.getFactory().createVariable();
                        variable.Name = element.Name;
                        variable.Value = pair.Value.ConvertBack(element.Type);
                        retVal.set(variable);
                    }
                    else
                    {
                        throw new FaultException<EFSServiceFault>(
                            new EFSServiceFault("Cannot find element named " + element.Name + " in structure " +
                                                structureType.FullName));
                    }
                }
            }

            CheckReturnValue(retVal, type);
            return retVal;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <param name="type"></param>
        public SyntheticVariable(object enclosing, string name, Type type)
        {
            Enclosing = enclosing;
            Name = name;
            Type = type;

            DeclaredElements = null;
        }
            GetStandardValues(ITypeDescriptorContext context)
            {
                ItemEditor editor = (ItemEditor)context.Instance;

                DataDictionary.Types.NameSpace nameSpace = editor.Item.NameSpace;
                DataDictionary.Types.Type      type      = editor.Item.Type;

                return(GetValues(nameSpace, type));
            }
Пример #13
0
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="type">The type in which the cast is performed</param>
        public Cast(Type type)
            : base(type.EFSSystem, type.Name)
        {
            TargetType = type;

            Value = (Parameter) acceptor.getFactory().createParameter();
            Value.Name = "Value";
            Value.Type = EFSSystem.AnyType;
            Value.setFather(this);
            FormalParameters.Add(Value);
        }
Пример #14
0
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="type">The type in which the cast is performed</param>
        public Cast(Type type)
            : base(type.EFSSystem, type.Name)
        {
            TargetType = type;

            Value      = (Parameter)acceptor.getFactory().createParameter();
            Value.Name = "Value";
            Value.Type = EFSSystem.AnyType;
            Value.setFather(this);
            FormalParameters.Add(Value);
        }
Пример #15
0
        /// <summary>
        ///     Provides the type of this expression
        /// </summary>
        /// <returns></returns>
        public override Type GetExpressionType()
        {
            Type retVal = null;

            if (IteratorExpression != null)
            {
                retVal = IteratorExpression.GetExpressionType();
            }

            return(retVal);
        }
Пример #16
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)
            {
                // Binding expression
                if (BindingExpression != null)
                {
                    BindingExpression.SemanticAnalysis(instance, IsRightSide.INSTANCE);
                    StaticUsage.AddUsages(BindingExpression.StaticUsage, Usage.ModeEnum.Read);

                    Type bindingExpressionType = BindingExpression.GetExpressionType();
                    if (bindingExpressionType != null)
                    {
                        StaticUsage.AddUsage(bindingExpressionType, Root, Usage.ModeEnum.Type);
                        BoundVariable.Type = bindingExpressionType;
                    }
                    else
                    {
                        AddError("Cannot determine binding expression type for " + ToString(), RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    AddError("Binding expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }


                // The evaluated expression
                if (Expression != null)
                {
                    Expression.SemanticAnalysis(instance, expectation);
                    StaticUsage.AddUsages(Expression.StaticUsage, Usage.ModeEnum.Read);
                }
                else
                {
                    AddError("Value expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return(retVal);
        }
        /// <summary>
        ///     Checks the expression and appends errors to the root tree node when inconsistencies are found
        /// </summary>
        public override void CheckExpression()
        {
            base.CheckExpression();

            if (ListExpression != null)
            {
                ListExpression.CheckExpression();

                Type listExpressionType = ListExpression.GetExpressionType();
                if (!(listExpressionType is Collection))
                {
                    AddError("List expression " + ListExpression + " should hold a collection", RuleChecksEnum.SyntaxError);
                }
            }
            else
            {
                AddError("List expression should be provided", RuleChecksEnum.SyntaxError);
            }
        }
Пример #18
0
        /// <summary>
        ///     Provides the value associated to this Expression
        /// </summary>
        /// <param name="context">The context on which the value must be found</param>
        /// <param name="explain">The explanation to fill, if any</param>
        /// <returns></returns>
        protected internal override IValue GetValue(InterpretationContext context, ExplanationPart explain)
        {
            IValue retVal = null;

            ListValue value = ListExpression.GetValue(context, explain) as ListValue;

            if (value != null)
            {
                int token = PrepareIteration(context);
                context.LocalScope.SetVariable(AccumulatorVariable);

                Type resultType = GetExpressionType();
                if (resultType != null)
                {
                    AccumulatorVariable.Value = resultType.getValue("0");
                    foreach (IValue v in value.Val)
                    {
                        if (v != EfsSystem.Instance.EmptyValue)
                        {
                            // All elements should always be != from EmptyValue
                            ElementFound           = true;
                            IteratorVariable.Value = v;
                            if (ConditionSatisfied(context, explain))
                            {
                                MatchingElementFound      = true;
                                AccumulatorVariable.Value = Accumulator.GetValue(context, explain);
                            }
                        }
                        NextIteration();
                    }
                }
                EndIteration(context, explain, token);

                retVal = AccumulatorVariable.Value;
            }

            return(retVal);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="enclosing"></param>
 /// <param name="name"></param>
 /// <param name="type"></param>
 public SyntheticVariable(object enclosing, string name, Type type)
 {
     Enclosing = enclosing;
     Name = name;
     Type = type;
 }
Пример #20
0
 /// <summary>
 /// Actions to be taken when the variable's value changes
 /// </summary>
 /// <param name="cacheImpact"></param>
 public void HandleChange(CacheImpact cacheImpact)
 {
     Type.HandleChange(cacheImpact);
 }
Пример #21
0
        /// <summary>
        /// Appends the corresponding type to the name space
        /// </summary>
        /// <param name="nameSpace">The namespace in which the type must be added</param>
        /// <param name="name">the name of the type</param>
        /// <param name="type">the type to convert</param>
        private DataDictionary.Types.Type AppendType(DataDictionary.Types.NameSpace nameSpace, string name, ErtmsSolutions.CodecNT.Type type)
        {
            DataDictionary.Types.Type retVal = null;

            if (EFSType(type) == null)
            {
                if (type.value is UiValue)
                {
                    UiValue uiValue = type.value as UiValue;

                    List <DataDictionary.Constants.EnumValue> values = getSpecialValues(uiValue.special_or_reserved_values);

                    Decimal maxValue = twoPow(type.length) - 1;
                    if (IsEnumeration(values, maxValue))
                    {
                        DataDictionary.Types.Enum enumeration = (DataDictionary.Types.Enum)DataDictionary.Generated.acceptor.getFactory().createEnum();
                        enumeration.Name    = type.id;
                        enumeration.Default = values[0].Name;
                        foreach (DataDictionary.Constants.EnumValue value in values)
                        {
                            enumeration.appendValues(value);
                        }

                        nameSpace.appendEnumerations(enumeration);
                        retVal = enumeration;
                    }
                    else
                    {
                        DataDictionary.Types.Range range = (DataDictionary.Types.Range)DataDictionary.Generated.acceptor.getFactory().createRange();
                        range.Name = type.id;

                        double factor = 1.0;

                        System.Globalization.CultureInfo info = System.Globalization.CultureInfo.InvariantCulture;
                        ResolutionFormula resolutionFormula   = uiValue.resolution_formula;
                        if (resolutionFormula != null && resolutionFormula.Value != null)
                        {
                            factor = double.Parse(resolutionFormula.Value, info);

                            // In that case the precision is integer
                            range.setPrecision(DataDictionary.Generated.acceptor.PrecisionEnum.aIntegerPrecision);
                            range.MinValue = "0";
                            range.MaxValue = "" + maxValue;
                            range.Default  = "0";
                        }

                        else
                        {
                            if (Math.Round(factor) == factor)
                            {
                                // Integer precision
                                range.setPrecision(DataDictionary.Generated.acceptor.PrecisionEnum.aIntegerPrecision);
                                range.MinValue = "0";
                                range.MaxValue = "" + maxValue * new Decimal(factor);
                                range.Default  = "0";
                            }
                            else
                            {
                                // Double precision
                                range.setPrecision(DataDictionary.Generated.acceptor.PrecisionEnum.aDoublePrecision);
                                range.MinValue = "0.0";
                                range.MaxValue = (maxValue * new Decimal(factor)).ToString(info);
                                range.Default  = "0.0";
                            }
                        }

                        foreach (DataDictionary.Constants.EnumValue value in values)
                        {
                            range.appendSpecialValues(value);
                        }

                        nameSpace.appendRanges(range);
                        retVal = range;
                    }
                }
                else if (type.value is CharValue)
                {
                    CharValue charValue = type.value as CharValue;

                    // Nothing to do : translated into string
                }
                else if (type.value is BcdValue)
                {
                    BcdValue bcdValue = type.value as BcdValue;

                    DataDictionary.Types.Range range = (DataDictionary.Types.Range)DataDictionary.Generated.acceptor.getFactory().createRange();
                    range.Name     = type.id;
                    range.MinValue = "0";
                    range.MaxValue = "" + (twoPow(type.length) - 1);
                    range.Default  = "0";

                    nameSpace.appendRanges(range);
                    retVal = range;
                }

                if (retVal != null)
                {
                    retVal.Comment = type.short_description;
                    if (type.description != null)
                    {
                        retVal.Comment = retVal.Comment + "\n" + type.description;
                    }
                }
            }

            return(retVal);
        }
Пример #22
0
        /// <summary>
        ///     Provides the type of this expression
        /// </summary>
        /// <returns></returns>
        public override Type GetExpressionType()
        {
            Type retVal = ListExpression.GetExpressionType();

            return(retVal);
        }
Пример #23
0
        /// <summary>
        ///     Provides the type associated to the name
        /// </summary>
        /// <param name="nameSpace">the namespace in which the name should be found</param>
        /// <param name="name"></param>
        /// <returns></returns>
        public Type FindType(Types.NameSpace nameSpace, string name)
        {
            Type retVal = null;

            Dictionary <string, Type> definedTypes = DefinedTypes;

            if (name != null)
            {
                if (nameSpace != null)
                {
                    ISubDeclaratorUtils.CriticalSection.WaitOne();
                    try
                    {
                        if (!_cache.ContainsKey(nameSpace))
                        {
                            _cache[nameSpace] = new Dictionary <string, Type>();
                        }
                        Dictionary <string, Type> subCache = _cache[nameSpace];

                        if (!subCache.ContainsKey(name))
                        {
                            Type tmp = null;

                            if (!Utils.Util.isEmpty(name))
                            {
                                tmp = nameSpace.findTypeByName(name);

                                if (tmp == null)
                                {
                                    if (definedTypes.ContainsKey(name))
                                    {
                                        tmp = definedTypes[name];
                                    }
                                }

                                if (tmp == null && definedTypes.ContainsKey("Default." + name))
                                {
                                    tmp = definedTypes["Default." + name];
                                }
                            }

                            subCache[name] = tmp;
                        }

                        retVal = subCache[name];
                    }
                    finally
                    {
                        ISubDeclaratorUtils.CriticalSection.ReleaseMutex();
                    }
                }
                else
                {
                    if (definedTypes.ContainsKey(name))
                    {
                        retVal = definedTypes[name];
                    }
                    else if (definedTypes.ContainsKey("Default." + name))
                    {
                        retVal = definedTypes["Default." + name];
                    }
                }
            }

            return(retVal);
        }
        /// <summary>
        ///     Converts the value provided as an EFS value
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public override IValue ConvertBack(Type type)
        {
            // TODO : Cannot receive a function from the external world

            throw new NotImplementedException();
        }
Пример #25
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="enclosing"></param>
 /// <param name="name"></param>
 /// <param name="type"></param>
 public SyntheticVariable(object enclosing, string name, Type type)
 {
     Enclosing = enclosing;
     Name      = name;
     Type      = type;
 }
Пример #26
0
        /// <summary>
        ///     Converts the value provided as an EFS value
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public override IValue ConvertBack(Type type)
        {
            // TODO : Cannot receive a function from the external world

            throw new NotImplementedException();
        }
Пример #27
0
        /// <summary>
        ///     Ensures that the element is used somewhere
        /// </summary>
        /// <param name="model"></param>
        private void checkUsage(ModelElement model)
        {
            List <Usage> references;

            Type type = model as Type;

            if (type != null && !(type is ICallable))
            {
                bool         checkType    = true;
                StateMachine stateMachine = type as StateMachine;
                if (stateMachine != null)
                {
                    checkType = stateMachine.EnclosingStateMachine == null;
                }

                if (checkType)
                {
                    references = EfsSystem.Instance.FindReferences(type);
                    if (references.Count == 0)
                    {
                        model.AddWarning("Type is declared but never used");
                    }
                }
            }
            else
            {
                IVariable variable = model as IVariable;
                if (variable != null)
                {
                    references = EfsSystem.Instance.FindReferences(variable as ModelElement);
                    bool read    = false;
                    bool written = variable.Mode == acceptor.VariableModeEnumType.aConstant;

                    foreach (Usage usage in references)
                    {
                        switch (usage.Mode)
                        {
                        case Usage.ModeEnum.Read:
                            read = true;
                            break;

                        case Usage.ModeEnum.Write:
                            written = true;
                            break;

                        case Usage.ModeEnum.ReadAndWrite:
                            read    = true;
                            written = true;
                            break;

                        default:
                            break;
                        }
                    }

                    if (!read && !written)
                    {
                        model.AddWarning("Variable is never read nor written");
                    }
                    else
                    {
                        if (!read)
                        {
                            model.AddWarning("Variable is never read");
                        }
                        if (!written)
                        {
                            model.AddWarning("Variable is never written");
                        }
                    }
                }
                else
                {
                    ICallable callable = model as ICallable;
                    if (callable != null)
                    {
                        references = EfsSystem.Instance.FindReferences(callable as ModelElement);
                        bool called = false;

                        foreach (Usage usage in references)
                        {
                            switch (usage.Mode)
                            {
                            case Usage.ModeEnum.Call:
                                called = true;
                                break;
                            }
                        }

                        if (!called)
                        {
                            model.AddWarning("Function or procedure is never called");
                        }
                    }
                }
            }
        }
Пример #28
0
        public StandardValuesCollection GetValues(DataDictionary.Types.NameSpace nameSpace, DataDictionary.Types.Type type)
        {
            Utils.FinderRepository.INSTANCE.ClearCache();

            List <string> retVal = new List <string>();

            if (type != null)
            {
                string prefix = type.FullName;
                if (nameSpace == type.NameSpace && nameSpace != null)
                {
                    prefix = prefix.Substring(nameSpace.FullName.Length + 1);
                }
                DataDictionary.OverallValueFinder.INSTANCE.findAllValueNames(prefix, type, false, retVal);
                retVal.Sort();
            }

            return(new StandardValuesCollection(retVal));
        }
Пример #29
0
            private void displayType(int indent, Type type)
            {
                Structure structureType = type as Structure;
                if (structureType != null)
                {
                    foreach (StructureElement element in structureType.Elements)
                    {
                        displayIndent(indent);
                        Type subType = element.Type;
                        Writer.WriteLine(element.Name + " : " + subType.FullName);
                        displayType(indent + 1, subType);
                    }
                }

                Range rangeType = type as Range;
                if (rangeType != null)
                {
                    displayIndent(indent);
                    Writer.WriteLine("RANGE " + rangeType.MinValueAsDouble + ".." + rangeType.MaxValueAsDouble +
                                     " DEFAULT VALUE = " + rangeType.DefaultValue.LiteralName);
                }

                Collection collectionType = type as Collection;
                if (collectionType != null)
                {
                    displayIndent(indent);
                    Type subType = collectionType.Type;
                    Writer.WriteLine("COLLECTION [" + collectionType.getMaxSize() + "] OF " + subType.FullName);
                    displayType(indent + 1, subType);
                }
            }