コード例 #1
0
 /// <summary>
 ///     Sets the value associated to the explanation
 /// </summary>
 /// <param name="explain"></param>
 /// <param name="namable"></param>
 public static void SetNamable(ExplanationPart explain, INamable namable)
 {
     if (explain != null)
     {
         explain.RightPart = namable;
     }
 }
コード例 #2
0
    public static string GetUniqueName <T>(this INamable namable, string newName, string oldName, IList <T> array) where T : INamable
    {
        int    suffix      = 0;
        bool   uniqueName  = false;
        string currentName = "";

        while (!uniqueName)
        {
            uniqueName  = true;
            currentName = newName;
            if (suffix > 0)
            {
                currentName += suffix.ToString();
            }

            foreach (INamable element in array)
            {
                if (element != namable && element.Name == currentName && element.Name != oldName)
                {
                    uniqueName = false;
                    break;
                }
            }
            suffix += 1;
        }
        return(currentName);
    }
コード例 #3
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="element">The element for which this explanation part is created</param>
 /// <param name="message">The message to display. MAKE SURE you do not use string concatenation to create this message</param>
 /// <param name="rightPart">The value associated to the message, if any</param>
 public ExplanationPart(ModelElement element, string message, INamable rightPart = null)
 {
     Element         = element;
     Message         = message;
     RightPart       = rightPart;
     SubExplanations = new List <ExplanationPart>();
 }
コード例 #4
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="element">The element for which this explanation part is created</param>
 /// <param name="leftPart">The left path to associate to this explanation</param>
 /// <param name="rightPart">The value associate to this left part</param>
 public ExplanationPart(ModelElement element, object leftPart, INamable rightPart = null)
 {
     Element         = element;
     LeftPart        = leftPart;
     RightPart       = rightPart;
     SubExplanations = new List <ExplanationPart>();
 }
コード例 #5
0
        public static string GetUniqueName(this INamable namable, IList <INamable> array, string newName, string oldName)
        {
            int    suffix      = 0;
            bool   uniqueName  = false;
            string currentName = "";

            while (!uniqueName)
            {
                uniqueName  = true;
                currentName = newName;
                if (suffix > 0)
                {
                    currentName += suffix.ToString();
                }

                for (int i = 0; i < array.Count; i++)
                {
                    INamable element = array[i];

                    if (element != namable && element.Name == currentName && element.Name != oldName)
                    {
                        uniqueName = false;
                        break;
                    }
                }

                suffix += 1;
            }
            return(currentName);
        }
コード例 #6
0
        /// <summary>
        ///     Provides the value of the prefix of the expression
        /// </summary>
        /// <param name="context">The context on which the value must be found</param>
        /// <param name="elementCount">The number of elements to consider</param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public INamable GetPrefixValue(InterpretationContext context, int elementCount, ExplanationPart explain)
        {
            INamable retVal = null;

            InterpretationContext ctxt = new InterpretationContext(context);

            for (int i = 0; i < elementCount; i++)
            {
                if (retVal != null)
                {
                    ctxt.Instance = retVal;
                }
                retVal = Arguments[i].GetValue(ctxt, explain);
                if (retVal == null)
                {
                    retVal = Arguments[i].Ref;
                }

                if (retVal == EfsSystem.Instance.EmptyValue)
                {
                    break;
                }
            }

            if (retVal == null)
            {
                AddError(ToString() + " prefix does not refer to a value", RuleChecksEnum.ExecutionFailed);
            }

            return(retVal);
        }
コード例 #7
0
        /// <summary>
        /// Indicates whether this expression references an instance
        /// </summary>
        /// <returns></returns>
        public override bool IsInstance()
        {
            bool retVal = true;

            int count = Arguments.Count;

            for (int i = count - 1; i >= 0; i--)
            {
                INamable aNamable = Arguments[i].Ref;
                if (aNamable is Variable ||
                    aNamable is Function ||
                    aNamable is Types.Enum ||
                    aNamable is Constants.EnumValue ||
                    aNamable is Constants.State)
                {
                    break;
                }
                if ((aNamable is NameSpace) ||
                    (aNamable is Structure))
                {
                    retVal = Arguments[i].IsInstance();
                    break;
                }
            }

            return(retVal);
        }
コード例 #8
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="id"></param>
 /// <param name="instance"></param>
 /// <param name="priority"></param>
 public ModelEvent(string id, INamable instance, acceptor.RulePriority?priority)
 {
     Id       = id;
     Message  = id;
     Instance = instance;
     Priority = priority;
 }
コード例 #9
0
        /// <summary>
        /// Provides the textual representation of the namable provided
        /// </summary>
        /// <param name="namable"></param>
        /// <returns></returns>
        public String explainNamable(INamable namable)
        {
            String retVal = "";

            if (namable != null)
            {
                retVal = namable.Name;

                Function fonction = namable as Function;
                if (fonction != null)
                {
                    if (fonction.Graph != null)
                    {
                        retVal = fonction.Graph.ToString();
                    }
                    else if (fonction.Surface != null)
                    {
                        retVal = fonction.Surface.ToString();
                    }
                }
                else
                {
                    Values.IValue value = namable as Values.IValue;
                    if (value != null)
                    {
                        retVal = value.LiteralName;
                    }
                }
            }

            return(retVal);
        }
コード例 #10
0
        /// <summary>
        ///     Indicates whether the declarator contains the value provided as parameter
        /// </summary>
        /// <param name="subDeclarator"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool ContainsValue(ISubDeclarator subDeclarator, INamable value)
        {
            bool retVal = false;

            if (subDeclarator != null)
            {
                CriticalSection.WaitOne();
                try
                {
                    List <INamable> tmp;
                    if (subDeclarator.DeclaredElements.TryGetValue(value.Name, out tmp))
                    {
                        foreach (INamable namable in tmp)
                        {
                            if (namable == value)
                            {
                                retVal = true;
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    CriticalSection.ReleaseMutex();
                }
            }

            return(retVal);
        }
コード例 #11
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="element">The element for which this explanation part is created</param>
 /// <param name="leftPart">The left path to associate to this explanation</param>
 /// <param name="rightPart">The value associate to this left part</param>
 public ExplanationPart(ModelElement element, object leftPart, INamable rightPart = null)
 {
     Element = element;
     LeftPart = leftPart;
     RightPart = rightPart;
     SubExplanations = new List<ExplanationPart>();
 }
コード例 #12
0
        /// <summary>
        /// Gets the reference of the designator if it covers the position given
        /// </summary>
        /// <param name="designator"></param>
        protected override void VisitDesignator(Designator designator)
        {
            if (ShouldCheck(designator))
            {
                Type type = designator.Ref as Type;
                if (Context == null && type != null)
                {
                    Context = type;
                }

                ITypedElement element = designator.Ref as ITypedElement;
                if (Context == null && element != null)
                {
                    Context = element;
                }

                ICallable callable = designator.Ref as ICallable;
                if (Context == null && callable != null)
                {
                    Context = callable;
                }

                NameSpace nameSpace = designator.Ref as NameSpace;
                if (Context == null && nameSpace != null)
                {
                    Context = nameSpace;
                }
            }
        }
コード例 #13
0
        /// <summary>
        ///     Adds a reference which satisfies the provided expectation in the result set
        /// </summary>
        /// <param name="namable"></param>
        /// <param name="expectation"></param>
        /// <param name="asType">Indicates that we had to move from instance to type to perform the deferencing</param>
        /// <param name="resultSet"></param>
        private int addReference(INamable namable, BaseFilter expectation, bool asType, ReturnValue resultSet)
        {
            int retVal = 0;

            if (namable != null)
            {
                if (expectation.AcceptableChoice(namable))
                {
                    if (asType)
                    {
                        if (!(namable is IValue) && !(namable is Type))
                        {
                            resultSet.Add(namable);
                            retVal += 1;
                        }
                        else if (namable is State)
                        {
                            // TODO : Refactor model to avoid this
                            resultSet.Add(namable);
                            retVal += 1;
                        }
                    }
                    else
                    {
                        resultSet.Add(namable);
                        retVal += 1;
                    }
                }
            }

            return(retVal);
        }
コード例 #14
0
        /// <summary>
        /// Provides the value associated to this Expression
        /// </summary>
        /// <param name="context">The context on which the value must be found</param>
        /// <returns></returns>
        public override Values.IValue GetValue(InterpretationContext context)
        {
            INamable retVal = Ref as Values.IValue;

            if (retVal == null)
            {
                InterpretationContext ctxt = new InterpretationContext(context);
                for (int i = 0; i < Arguments.Count; i++)
                {
                    if (retVal != null)
                    {
                        ctxt.Instance = retVal;
                    }
                    retVal = Arguments[i].GetValue(ctxt);

                    if (retVal == EFSSystem.EmptyValue)
                    {
                        break;
                    }
                }
            }

            if (retVal == null)
            {
                AddError(ToString() + " does not refer to a value");
            }

            return(retVal as Values.IValue);
        }
コード例 #15
0
        /// <summary>
        /// Provides the variable designated by this designator according to the interpretation context
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public IVariable GetVariable(InterpretationContext context)
        {
            INamable  reference = GetReference(context);
            IVariable retVal    = reference as IVariable;

            return(retVal);
        }
コード例 #16
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="id"></param>
 /// <param name="instance"></param>
 /// <param name="priority"></param>
 public ModelEvent(string id, INamable instance, acceptor.RulePriority? priority)
 {
     Id = id;
     Message = id;
     Instance = instance;
     Priority = priority;
 }
コード例 #17
0
ファイル: Window.cs プロジェクト: fakoor/ERTMSFormalSpecs
        /// <summary>
        ///     Allows to refresh the view, when the selected model changed
        /// </summary>
        /// <param name="context"></param>
        /// <returns>true if refresh should be performed</returns>
        public override bool HandleSelectionChange(Context.SelectionContext context)
        {
            bool retVal = base.HandleSelectionChange(context);

            if (retVal)
            {
                INamable namable = DisplayedModel;
                if (namable != null)
                {
                    Text = namable.Name + " history";
                }
                else
                {
                    Text = "History";
                }

                historyTreeView.Root = DisplayedModel;
                if (historyTreeView.Nodes.Count > 0)
                {
                    historyTreeView.SelectedNode = historyTreeView.Nodes[0] as ChangeTreeNode;
                }
                else
                {
                    historyTreeView.SelectedNode = null;
                    Properties.SelectedObject    = null;
                }
            }

            return(retVal);
        }
コード例 #18
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="instance">The instance on which interpretation should be performed</param>
 public InterpretationContext(INamable instance)
 {
     LocalScope      = new SymbolTable();
     Instance        = instance;
     UseDefaultValue = true;
     HasSideEffects  = false;
 }
コード例 #19
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="other">Copies the other interpretation context contents</param>
 /// <param name="instance">The evaluation instance</param>
 public InterpretationContext(InterpretationContext other, INamable instance)
 {
     LocalScope      = other.LocalScope;
     Instance        = instance;
     UseDefaultValue = true;
     HasSideEffects  = other.HasSideEffects;
 }
コード例 #20
0
        /// <summary>
        ///     Provides the instance related to a character index in the textbox
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        protected INamable GetInstance(int index)
        {
            INamable retVal = null;

            if (Model != null)
            {
                InterpreterTreeNode node = Parse(EditionTextBox.Text);
                if (node != null)
                {
                    ContextGrabber grabber = new ContextGrabber();
                    retVal = grabber.GetContext(index, node);
                }

                if (retVal == null)
                {
                    // Perform a fuzzy search by trying to find the corresponding expression text
                    string text = GetExpressionText(EditionTextBox.Text, index);
                    node  = Parse(text);
                    index = text.Length - 1;

                    if (node != null)
                    {
                        ContextGrabber grabber = new ContextGrabber();
                        retVal = grabber.GetContext(index, node);
                    }
                }
            }

            return(retVal);
        }
コード例 #21
0
        /// <summary>
        /// Provides the value of the prefix of the expression
        /// </summary>
        /// <param name="context">The context on which the value must be found</param>
        /// <param name="elementCount">The number of elements to consider</param>
        /// <returns></returns>
        public INamable GetPrefixValue(InterpretationContext context, int elementCount)
        {
            INamable retVal = null;

            InterpretationContext ctxt = new InterpretationContext(context);

            for (int i = 0; i < elementCount; i++)
            {
                if (retVal != null)
                {
                    ctxt.Instance = retVal;
                }
                retVal = Arguments[i].GetValue(ctxt);
                if (retVal == null)
                {
                    retVal = Arguments[i].Ref;
                }

                if (retVal == EFSSystem.EmptyValue)
                {
                    break;
                }
            }

            if (retVal == null)
            {
                AddError(ToString() + " prefix does not refer to a value");
            }

            return(retVal);
        }
コード例 #22
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)
            {
                // ListExpression
                if (ListExpression != null)
                {
                    ListExpression.SemanticAnalysis(instance, IsRightSide.INSTANCE);
                    StaticUsage.AddUsages(ListExpression.StaticUsage, Usage.ModeEnum.Read);

                    Collection collectionType = ListExpression.GetExpressionType() as Collection;
                    if (collectionType != null)
                    {
                        StaticUsage.AddUsage(collectionType, Root, Usage.ModeEnum.Type);
                        IteratorVariable.Type         = collectionType.Type;
                        PreviousIteratorVariable.Type = collectionType.Type;
                    }
                    else
                    {
                        AddError("Cannot determine collection type on list expression " + ToString(), RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    AddError("List expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return(retVal);
        }
コード例 #23
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);
        }
コード例 #24
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="element">The element for which this explanation part is created</param>
 /// <param name="message">The message to display. MAKE SURE you do not use string concatenation to create this message</param>
 /// <param name="rightPart">The value associated to the message, if any</param>
 public ExplanationPart(ModelElement element, string message, INamable rightPart = null)
 {
     Element = element;
     Message = message;
     RightPart = rightPart;
     SubExplanations = new List<ExplanationPart>();
 }
コード例 #25
0
        /// <summary>
        /// Gets the context (type or namespace) for a given position
        /// </summary>
        /// <param name="position">The position in the source text</param>
        /// <param name="node">The base node on which the search should be performed</param>
        /// <returns></returns>
        public INamable GetContext(int position, InterpreterTreeNode node)
        {
            Position = position;
            Context  = null;

            visitInterpreterTreeNode(node);

            return(Context);
        }
コード例 #26
0
        public Variables.IVariable GetVariable(InterpretationContext context)
        {
            Variables.IVariable retVal = null;

            INamable reference = getReference(context);

            retVal = reference as Variables.IVariable;

            return(retVal);
        }
コード例 #27
0
 /// <summary>
 /// Adds a reference which satisfies the provided expectation in the result set
 /// </summary>
 /// <param name="namable"></param>
 /// <param name="expectation"></param>
 /// <param name="resultSet"></param>
 private void addReference(INamable namable, Filter.AcceptableChoice expectation, ReturnValue resultSet)
 {
     if (namable != null)
     {
         if (expectation(namable))
         {
             resultSet.Add(namable);
         }
     }
 }
コード例 #28
0
    public static string GetUniqueName <T>(this INamable namable, string newName, string oldName, string emptyName, IList <T> array) where T : INamable
    {
        string name = namable.GetUniqueName(newName, oldName, array);

        if (string.IsNullOrEmpty(newName))
        {
            name = namable.GetUniqueName(emptyName, oldName, array);
        }
        return(name);
    }
コード例 #29
0
        private void EditionTextBox_MouseHover(object sender, EventArgs e)
        {
            Point    location = MouseLocation;
            INamable instance = GetInstance(location);

            location.Offset(10, 10);
            const bool considerMouseMove = true;

            ExplainAndShow(instance, location, considerMouseMove);
        }
コード例 #30
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);
        }
コード例 #31
0
        /// <summary>
        ///     Explains a list of namables and shows the associated textbox
        /// </summary>
        /// <param name="namable">The namable to explain</param>
        /// <param name="location">
        ///     The location where the explain box should be displayed. If empty is displayed, the location is
        ///     computed based on the combo box location
        /// </param>
        /// <param name="sensibleToMouseMove">Indicates that the explain box should be closed when the mouse moves</param>
        private void ExplainAndShow(INamable namable, Point location, bool sensibleToMouseMove)
        {
            explainRichTextBox.Text = "";
            if (namable != null)
            {
                TextualExplanation explanation    = new TextualExplanation();
                ITextualExplain    textualExplain = namable as ITextualExplain;
                if (textualExplain != null)
                {
                    textualExplain.GetExplain(explanation, false);
                }

                explainRichTextBox.Text = explanation.Text;
                explainRichTextBox.ProcessAllLines();

                if (location == Point.Empty)
                {
                    if (SelectionComboBox.DroppedDown)
                    {
                        explainRichTextBox.Location = new Point(
                            SelectionComboBox.Location.X + SelectionComboBox.Size.Width,
                            SelectionComboBox.Location.Y + SelectionComboBox.Size.Height
                            );
                    }
                    else
                    {
                        explainRichTextBox.Location = new Point(
                            SelectionComboBox.Location.X,
                            SelectionComboBox.Location.Y + SelectionComboBox.Size.Height
                            );
                    }
                }
                else
                {
                    explainRichTextBox.Location = new Point(
                        Math.Min(location.X, EditionTextBox.Size.Width - explainRichTextBox.Size.Width),
                        Math.Min(location.Y, EditionTextBox.Size.Height - explainRichTextBox.Size.Height));
                }

                ConsiderMouseMoveToCloseExplanation = sensibleToMouseMove;

                explainRichTextBox.Size = new Size(400, 200);
                if (explainRichTextBox.Size.Width >= Size.Width * 0.8)
                {
                    explainRichTextBox.Size = new Size((int)(Size.Width * 0.8), explainRichTextBox.Size.Height);
                }
                if (explainRichTextBox.Size.Height >= Size.Height * 0.8)
                {
                    explainRichTextBox.Size = new Size(explainRichTextBox.Size.Width, (int)(Size.Height * 0.8));
                }

                explainRichTextBox.Show();
                EditionTextBox.SendToBack();
            }
        }
コード例 #32
0
        /// <summary>
        ///     Predicate which indicates whether the namable provided matches the expectation for the semantic analysis
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool AcceptableChoice(INamable value)
        {
            bool retVal = base.AcceptableChoice(value);

            if (!retVal)
            {
                return value is Parameter;
            }

            return retVal;
        }
コード例 #33
0
        public static string GetUniqueName(this INamable namable, IList <INamable> array, string newName, string oldName, string emptyName)
        {
            string name = namable.GetUniqueName(array, newName, oldName);

            if (string.IsNullOrEmpty(newName))
            {
                name = namable.GetUniqueName(array, emptyName, oldName);
            }

            return(name);
        }
コード例 #34
0
        /// <summary>
        ///     Predicate which indicates whether the namable provided matches the expectation for the semantic analysis
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool AcceptableChoice(INamable value)
        {
            bool retVal = base.AcceptableChoice(value);

            if (!retVal)
            {
                retVal = IsCallable.Predicate(value);
            }

            return(retVal);
        }
コード例 #35
0
        /// <summary>
        ///     Predicate which indicates whether the namable provided matches the expectation for the semantic analysis
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool AcceptableChoice(INamable value)
        {
            bool retVal = base.AcceptableChoice(value);

            if (!retVal)
            {
                retVal = IsCallable.Predicate(value);
            }

            return retVal;
        }
コード例 #36
0
        /// <summary>
        ///     Performs the semantic analysis of the expression
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <paraparam name="expectation">Indicates the kind of element we are looking for</paraparam>
        /// <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)
            {
                // Iterator expression
                IteratorExpression.SemanticAnalysis(instance, AllMatches.INSTANCE);
                StaticUsage.AddUsages(IteratorExpression.StaticUsage, Usage.ModeEnum.Read);
            }

            return retVal;
        }
コード例 #37
0
ファイル: Rename.xaml.cs プロジェクト: tgckpg/wenku10
        public Rename( INamable Target, string Title, bool ReadOnly )
            : this()
        {
            NamingTarget = Target;
            NewName.Text = Target.Name;
            NewName.IsReadOnly = ReadOnly;

            NewName.SelectAll();

            if ( !string.IsNullOrEmpty( Title ) )
            {
                TitleBlock.Text = Title;
            }
        }
コード例 #38
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)
            {
                // Structure
                if (Structure != null)
                {
                    Structure.SemanticAnalysis(instance, IsStructure.INSTANCE);
                    StaticUsage.AddUsages(Structure.StaticUsage, Usage.ModeEnum.Type);

                    // Structure field Association
                    if (Associations != null)
                    {
                        Structure structureType = Structure.Ref as Structure;
                        foreach (KeyValuePair<Designator, Expression> pair in Associations)
                        {
                            if (structureType != null)
                            {
                                pair.Key.Ref = structureType.FindStructureElement(pair.Key.Image);
                                StaticUsage.AddUsage(pair.Key.Ref, Root, Usage.ModeEnum.Parameter);
                            }

                            pair.Value.SemanticAnalysis(instance, IsRightSide.INSTANCE);
                            StaticUsage.AddUsages(pair.Value.StaticUsage, Usage.ModeEnum.Read);
                        }
                    }
                }
            }

            return retVal;
        }
コード例 #39
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)
            {
                // Accumulator
                if (AccumulatorVariable != null)
                {
                    AccumulatorVariable.Type = GetExpressionType();
                }

                if (DefinedAccumulator != null)
                {
                    DefinedAccumulator.SemanticAnalysis(instance, AllMatches.INSTANCE);
                }

                if (Accumulator != null)
                {
                    Accumulator.SemanticAnalysis(instance, AllMatches.INSTANCE);
                    StaticUsage.AddUsages(Accumulator.StaticUsage, Usage.ModeEnum.Read);
                }
            }

            return retVal;
        }
コード例 #40
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");
                }

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

            return retVal;
        }
コード例 #41
0
        /// <summary>
        ///     Provides the enclosing sub declarator
        /// </summary>
        /// <param name="instance"></param>
        /// <returns></returns>
        private INamable EnclosingSubDeclarator(INamable instance)
        {
            INamable retVal = instance;

            do
            {
                retVal = enclosing(retVal);
            } while (retVal != null && !(retVal is ISubDeclarator));

            return retVal;
        }
コード例 #42
0
        /// <summary>
        ///     Adds a reference which satisfies the provided expectation in the result set
        /// </summary>
        /// <param name="namable"></param>
        /// <param name="expectation"></param>
        /// <param name="asType">Indicates that we had to move from instance to type to perform the deferencing</param>
        /// <param name="resultSet"></param>
        private int addReference(INamable namable, BaseFilter expectation, bool asType, ReturnValue resultSet)
        {
            int retVal = 0;

            if (namable != null)
            {
                if (expectation.AcceptableChoice(namable))
                {
                    if (asType)
                    {
                        if (!(namable is IValue) && !(namable is Type))
                        {
                            resultSet.Add(namable);
                            retVal += 1;
                        }
                        else if (namable is State)
                        {
                            // TODO : Refactor model to avoid this
                            resultSet.Add(namable);
                            retVal += 1;
                        }
                    }
                    else
                    {
                        resultSet.Add(namable);
                        retVal += 1;
                    }
                }
            }

            return retVal;
        }
コード例 #43
0
        /// <summary>
        ///     Provides the possible references for this designator (only available during semantic analysis)
        /// </summary>
        /// <param name="instance">the instance on which this element should be found.</param>
        /// <param name="expectation">the expectation on the element found</param>
        /// <param name="lastElement">Indicates that this element is the last one in a dereference chain</param>
        /// <returns></returns>
        public ReturnValue GetReferences(INamable instance, BaseFilter expectation, bool lastElement)
        {
            ReturnValue retVal = new ReturnValue(this);

            if (instance == null)
            {
                // Special handling for THIS or ENCLOSING
                if (Image == ThisKeyword || Image == EnclosingKeyword)
                {
                    INamable currentElem = Root;
                    while (currentElem != null)
                    {
                        Type type = currentElem as Type;
                        if (type != null)
                        {
                            StateMachine stateMachine = type as StateMachine;
                            while (stateMachine != null)
                            {
                                type = stateMachine;
                                stateMachine = stateMachine.EnclosingStateMachine;
                            }

                            // Enclosing does not references state machines.
                            if (!(Image == EnclosingKeyword && type is StateMachine))
                            {
                                retVal.Add(type);
                                return retVal;
                            }
                        }
                        currentElem = enclosing(currentElem);
                    }

                    return retVal;
                }

                // No enclosing instance. Try to first name of a . separated list of names
                //  . First in the enclosing expression
                InterpreterTreeNode current = this;
                while (current != null)
                {
                    ISubDeclarator subDeclarator = current as ISubDeclarator;
                    if (FillBySubdeclarator(subDeclarator, expectation, false, retVal) > 0)
                    {
                        // If this is the last element in the dereference chain, stop at first match
                        if (lastElement)
                        {
                            return retVal;
                        }
                        current = null;
                    }
                    else
                    {
                        current = current.Enclosing;
                    }
                }

                // . In the predefined elements
                addReference(EfsSystem.Instance.GetPredefinedItem(Image), expectation, false, retVal);
                if (lastElement && !retVal.IsEmpty)
                {
                    return retVal;
                }

                // . In the enclosing items, except the enclosing dictionary since dictionaries are handled in a later step
                INamable currentNamable = Root;
                while (currentNamable != null)
                {
                    ISubDeclarator subDeclarator = currentNamable as ISubDeclarator;
                    if (subDeclarator != null && !(subDeclarator is Dictionary))
                    {
                        if (FillBySubdeclarator(subDeclarator, expectation, false, retVal) > 0 && lastElement)
                        {
                            return retVal;
                        }
                    }

                    currentNamable = EnclosingSubDeclarator(currentNamable);
                }

                // . In the dictionaries declared in the system
                foreach (Dictionary dictionary in EfsSystem.Instance.Dictionaries)
                {
                    if (FillBySubdeclarator(dictionary, expectation, false, retVal) > 0 && lastElement)
                    {
                        return retVal;
                    }

                    NameSpace defaultNameSpace = dictionary.FindNameSpace("Default");
                    if (defaultNameSpace != null)
                    {
                        if (FillBySubdeclarator(defaultNameSpace, expectation, false, retVal) > 0 && lastElement)
                        {
                            return retVal;
                        }
                    }
                }
            }
            else
            {
                // The instance is provided, hence, this is not the first designator in the . separated list of designators
                bool asType = false;
                if (instance is ITypedElement && !(instance is State))
                {
                    // If the instance is a typed element, dereference it to its corresponding type
                    ITypedElement element = instance as ITypedElement;
                    if (element.Type != EfsSystem.Instance.NoType)
                    {
                        instance = element.Type;
                        asType = true;
                    }
                }

                // Find the element in all enclosing sub declarators of the instance
                while (instance != null)
                {
                    ISubDeclarator subDeclarator = instance as ISubDeclarator;
                    if (FillBySubdeclarator(subDeclarator, expectation, asType, retVal) > 0)
                    {
                        instance = null;
                    }
                    else
                    {
                        if (instance is Dictionary)
                        {
                            instance = EnclosingSubDeclarator(instance);
                        }
                        else
                        {
                            instance = null;
                        }
                    }
                }
            }

            return retVal;
        }
コード例 #44
0
 /// <summary>
 ///     Predicate, so that the code can be reused
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static bool Predicate(INamable value)
 {
     return value is IValue || value is Parameter;
 }
コード例 #45
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)
            {
                // Accumulator
                AccumulatorVariable.Type = GetExpressionType();

                if (DefinedAccumulator != null)
                {
                    DefinedAccumulator.SemanticAnalysis(instance, AllMatches.INSTANCE);

                    Accumulator.SemanticAnalysis(instance, AllMatches.INSTANCE);
                    StaticUsage.AddUsages(Accumulator.StaticUsage, Usage.ModeEnum.Read);
                }
                else
                {
                    AddError("Accumulator expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return retVal;
        }
コード例 #46
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)
            {
                if (Term != null)
                {
                    Term.SemanticAnalysis(instance, expectation, true);
                    StaticUsage = Term.StaticUsage;
                }
                else if (Expression != null)
                {
                    Expression.SemanticAnalysis(instance, expectation);
                    StaticUsage = Expression.StaticUsage;
                }
            }

            return retVal;
        }
コード例 #47
0
        /// <summary>
        ///     Provides the possible references types for this expression (used in semantic analysis)
        /// </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>
        /// <param name="last">indicates that this is the last element in a dereference chain</param>
        /// <returns></returns>
        public override ReturnValue GetReferenceTypes(INamable instance, BaseFilter expectation, bool last)
        {
            ReturnValue retVal = ReturnValue.Empty;

            if (Term != null)
            {
                retVal = Term.GetReferenceTypes(instance, expectation, last);
            }
            else
            {
                if (Expression != null)
                {
                    retVal = Expression.GetReferenceTypes(instance, expectation, true);
                }
            }

            return retVal;
        }
コード例 #48
0
 /// <summary>
 ///     Predicate, so that the code can be reused
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static bool Predicate(INamable value)
 {
     return value is Type;
 }
コード例 #49
0
 /// <summary>
 ///     Predicate which indicates whether the namable provided matches the expectation for the semantic analysis
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public override bool AcceptableChoice(INamable value)
 {
     return Predicate(value);
 }
コード例 #50
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)
            {
                // Value
                Value.SemanticAnalysis(instance);
                StaticUsage.AddUsages(Value.StaticUsage, Usage.ModeEnum.Read);

                // ListExpression
                ListExpression.SemanticAnalysis(instance, IsLeftSide.INSTANCE);
                StaticUsage.AddUsages(ListExpression.StaticUsage, Usage.ModeEnum.ReadAndWrite);

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

            return retVal;
        }
コード例 #51
0
        /// <summary>
        ///     Performs the semantic analysis of the term
        /// </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>
        /// <param name="lastElement">Indicates that this element is the last one in a dereference chain</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public void SemanticAnalysis(INamable instance, BaseFilter expectation, bool lastElement)
        {
            ReturnValue tmp = GetReferences(instance, expectation, lastElement);
            if (Image != ThisKeyword && Image != EnclosingKeyword)
            {
                tmp.Filter(expectation);
            }
            if (tmp.IsUnique)
            {
                Ref = tmp.Values[0].Value;
            }

            if (StaticUsage == null)
            {
                StaticUsage = new Usages();
                StaticUsage.AddUsage(Ref, Root, null);
            }
        }
コード例 #52
0
        /// <summary>
        ///     Creates a sub explanation for the explain provided as parameter
        /// </summary>
        /// <param name="explain"></param>
        /// <param name="leftPart"></param>
        /// <param name="rightPart"></param>
        /// <returns></returns>
        public static ExplanationPart CreateSubExplanation(ExplanationPart explain, object leftPart,
            INamable rightPart = null)
        {
            ExplanationPart retVal = null;

            if (explain != null)
            {
                retVal = new ExplanationPart(explain.Element, leftPart, rightPart);
                explain.SubExplanations.Add(retVal);
            }

            return retVal;
        }
コード例 #53
0
        /// <summary>
        ///     Provides the enclosing element
        /// </summary>
        /// <param name="retVal"></param>
        /// <returns></returns>
        private INamable enclosing(INamable retVal)
        {
            IEnclosed enclosed = retVal as IEnclosed;

            if (enclosed != null)
            {
                retVal = enclosed.Enclosing as INamable;
            }
            else
            {
                retVal = null;
            }

            return retVal;
        }
コード例 #54
0
 /// <summary>
 ///     Sets the value associated to the explanation
 /// </summary>
 /// <param name="explain"></param>
 /// <param name="namable"></param>
 public static void SetNamable(ExplanationPart explain, INamable namable)
 {
     if (explain != null)
     {
         explain.RightPart = namable;
     }
 }
コード例 #55
0
        /// <summary>
        /// Indicates whether the list of object references contains the provided model element
        /// </summary>
        /// <param name="choices"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        private bool Contains(IEnumerable<ObjectReference> choices, INamable model)
        {
            bool retVal = false;

            foreach (ObjectReference objectReference in choices)
            {
                if (objectReference.Model == model)
                {
                    retVal = true;
                    break;
                }
            }

            return retVal;
        }
コード例 #56
0
        /// <summary>
        ///     Provides the possible references for this expression (only available during semantic analysis)
        /// </summary>
        /// <param name="instance">the instance on which this element should be found.</param>
        /// <param name="expectation">the expectation on the element found</param>
        /// <param name="last">indicates that this is the last element in a dereference chain</param>
        /// <returns></returns>
        public override ReturnValue getReferences(INamable instance, BaseFilter expectation, bool last)
        {
            ReturnValue retVal = Arguments[0].getReferences(instance, AllMatches.INSTANCE, false);

            if (retVal.IsEmpty)
            {
                retVal = Arguments[0].getReferenceTypes(instance, AllMatches.INSTANCE, false);
            }

            // When variables & parameters are found, only consider the first one
            // which is the one that is closer in the tree
            {
                ReturnValue tmp2 = retVal;
                retVal = new ReturnValue();

                ReturnValueElement variable = null;
                foreach (ReturnValueElement elem in tmp2.Values)
                {
                    if (elem.Value is Parameter || elem.Value is IVariable)
                    {
                        if (variable == null)
                        {
                            variable = elem;
                            retVal.Values.Add(elem);
                        }
                    }
                    else
                    {
                        retVal.Values.Add(elem);
                    }
                }
            }

            if (!retVal.IsEmpty)
            {
                for (int i = 1; i < Arguments.Count; i++)
                {
                    ReturnValue tmp2 = retVal;
                    retVal = new ReturnValue(Arguments[i]);

                    foreach (ReturnValueElement elem in tmp2.Values)
                    {
                        bool removed = false;
                        ModelElement model = elem.Value as ModelElement;
                        if (model != null)
                        {
                            removed = model.IsRemoved;
                        }

                        if (!removed)
                        {
                            retVal.Merge(elem,
                                Arguments[i].getReferences(elem.Value, AllMatches.INSTANCE, i == (Arguments.Count - 1)));
                        }
                    }

                    if (retVal.IsEmpty)
                    {
                        AddError("Cannot find " + Arguments[i].ToString() + " in " + Arguments[i - 1].ToString());
                    }
                }
            }
            else
            {
                AddError("Cannot evaluate " + Arguments[0].ToString());
            }

            retVal.filter(expectation);

            return retVal;
        }
コード例 #57
0
        /// <summary>
        ///     Provides the textual representation of the namable provided
        /// </summary>
        /// <param name="namable"></param>
        /// <returns></returns>
        private string explainNamable(INamable namable)
        {
            string retVal = "";

            if (namable != null)
            {
                retVal = namable.Name;

                Function fonction = namable as Function;
                if (fonction != null)
                {
                    if (fonction.Graph != null)
                    {
                        retVal = fonction.Graph.ToString();
                    }
                    else if (fonction.Surface != null)
                    {
                        retVal = fonction.Surface.ToString();
                    }
                }
                else
                {
                    IValue value = namable as IValue;
                    if (value != null)
                    {
                        retVal = value.LiteralName;
                    }
                }
            }

            return retVal;
        }
コード例 #58
0
        /// <summary>
        ///     Performs the semantic analysis of the expression
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <paraparam name="expectation">Indicates the kind of element we are looking for</paraparam>
        /// <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)
            {
                Ref = null;

                ReturnValue tmp = getReferences(instance, expectation, false);

                if (tmp.IsUnique)
                {
                    // Unique element has been found. Reference it and perform the semantic analysis
                    // on all dereferenced expression, now that the context is known for each expression
                    Ref = tmp.Values[0].Value;
                    StaticUsage.AddUsage(Ref, Root, null);

                    References referenceFilter;
                    ReturnValueElement current = tmp.Values[0];
                    for (int i = Arguments.Count - 1; i > 0; i--)
                    {
                        referenceFilter = new References(current.Value);
                        current = current.PreviousElement;
                        Arguments[i].SemanticAnalysis(current.Value, referenceFilter);
                        StaticUsage.AddUsages(Arguments[i].StaticUsage, null);
                        StaticUsage.AddUsage(Arguments[i].Ref, Root, null);
                    }
                    referenceFilter = new References(current.Value);
                    Arguments[0].SemanticAnalysis(null, referenceFilter);
                    StaticUsage.AddUsages(Arguments[0].StaticUsage, null);
                    StaticUsage.AddUsage(Arguments[0].Ref, Root, null);
                }
                else if (tmp.IsAmbiguous)
                {
                    // Several possible interpretations for this deref expression, not allowed
                    AddError("Expression " + ToString() + " may have several interpretations " + tmp.ToString() +
                             ", please disambiguate");
                }
                else
                {
                    // No possible interpretation for this deref expression, not allowed
                    AddError("Expression " + ToString() + " has no interpretation");
                }
            }

            return retVal;
        }
コード例 #59
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 semantical analysis should be performed</returns>
        public virtual bool SemanticAnalysis(INamable instance = null)
        {
            bool retVal = !SemanticalAnalysisDone;

            if (retVal)
            {
                StaticUsage = new Usages();
                SemanticalAnalysisDone = true;
            }

            return retVal;
        }
コード例 #60
0
 /// <summary>
 ///     Predicate, so that the code can be reused
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static bool Predicate(INamable value)
 {
     return (value is IValue);
 }