예제 #1
0
        /// <summary>
        ///     Visits a tree node
        /// </summary>
        /// <param name="interpreterTreeNode"></param>
        protected virtual void visitInterpreterTreeNode(InterpreterTreeNode interpreterTreeNode)
        {
            Designator designator = interpreterTreeNode as Designator;

            if (designator != null)
            {
                VisitDesignator(designator);
            }

            Term term = interpreterTreeNode as Term;

            if (term != null)
            {
                VisitTerm(term);
            }

            Expression expression = interpreterTreeNode as Expression;

            if (expression != null)
            {
                VisitExpression(expression);
            }

            Statement.Statement statement = interpreterTreeNode as Statement.Statement;
            if (statement != null)
            {
                VisitStatement(statement);
            }
        }
예제 #2
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);
        }
        /// <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;
        }
예제 #4
0
        /// <summary>
        ///     Visits an interpreter tree node
        /// </summary>
        /// <param name="interpreterTreeNode"></param>
        protected virtual void VisitInterpreterTreeNode(InterpreterTreeNode interpreterTreeNode)
        {
            Expression expression = interpreterTreeNode as Expression;

            if (expression != null)
            {
                VisitExpression(expression);
            }
            else
            {
                Statement.Statement statement = interpreterTreeNode as Statement.Statement;
                if (statement != null)
                {
                    VisitStatement(statement);
                }
                else
                {
                    Term term = interpreterTreeNode as Term;
                    if (term != null)
                    {
                        VisitTerm(term);
                    }
                    else
                    {
                        Designator designator = interpreterTreeNode as Designator;
                        if (designator != null)
                        {
                            VisitDesignator(designator);
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public ReturnValue(InterpreterTreeNode node)
 {
     Node   = node;
     Values = new List <ReturnValueElement>();
 }
예제 #6
0
 /// <summary>
 ///     Visits an interpreter tree node
 /// </summary>
 /// <param name="interpreterTreeNode"></param>
 protected virtual void VisitInterpreterTreeNode(InterpreterTreeNode interpreterTreeNode)
 {
     Expression expression = interpreterTreeNode as Expression;
     if (expression != null)
     {
         VisitExpression(expression);
     }
     else
     {
         Statement.Statement statement = interpreterTreeNode as Statement.Statement;
         if (statement != null)
         {
             VisitStatement(statement);
         }
         else
         {
             Term term = interpreterTreeNode as Term;
             if (term != null)
             {
                 VisitTerm(term);
             }
             else
             {
                 Designator designator = interpreterTreeNode as Designator;
                 if (designator != null)
                 {
                     VisitDesignator(designator);
                 }
                 else
                 {
                     throw new NotImplementedException();
                 }
             }
         }
     }
 }
예제 #7
0
        /// <summary>
        ///     Visits a tree node
        /// </summary>
        /// <param name="interpreterTreeNode"></param>
        protected virtual void visitInterpreterTreeNode(InterpreterTreeNode interpreterTreeNode)
        {
            Designator designator = interpreterTreeNode as Designator;
            if (designator != null)
            {
                VisitDesignator(designator);
            }

            Term term = interpreterTreeNode as Term;
            if (term != null)
            {
                VisitTerm(term);
            }

            Expression expression = interpreterTreeNode as Expression;
            if (expression != null)
            {
                VisitExpression(expression);
            }

            Statement.Statement statement = interpreterTreeNode as Statement.Statement;
            if (statement != null)
            {
                VisitStatement(statement);
            }
        }
예제 #8
0
 /// <summary>
 /// Indicates if the node belongs to the search
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 private bool ShouldCheck(InterpreterTreeNode node)
 {
     return((Context == null) && (node.Start <= Position && Position <= node.End));
 }
예제 #9
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);
        }
예제 #10
0
 /// <summary>
 ///     Takes an interpreter tree into consideration
 /// </summary>
 /// <param name="tree"></param>
 private void ConsiderInterpreterTreeNode(InterpreterTreeNode tree)
 {
     if (tree != null && tree.StaticUsage != null)
     {
         if (Model != null)
         {
             List<Usage> usages = tree.StaticUsage.Find(Model);
             foreach (Usage usage in usages)
             {
                 Usages.Add(usage);
             }
         }
         else
         {
             foreach (Usage usage in tree.StaticUsage.AllUsages)
             {
                 if (Filter.AcceptableChoice(usage.Referenced))
                 {
                     Usages.Add(usage);
                 }
             }
         }
     }
 }
예제 #11
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ReturnValue(InterpreterTreeNode node)
 {
     Node = node;
     Values = new List<ReturnValueElement>();
 }
예제 #12
0
                /// <summary>
                ///     Updates the dependancy graph according to this expression tree
                /// </summary>
                /// <param name="dependantFunction" />
                /// <param name="tree"></param>
                public void UpdateReferences(Function dependantFunction, InterpreterTreeNode tree)
                {
                    DependantFunction = dependantFunction;

                    visitInterpreterTreeNode(tree);
                }
예제 #13
0
                /// <summary>
                ///     Updates the dependancy graph according to this expression tree
                /// </summary>
                /// <param name="dependantFunction" />
                /// <param name="tree"></param>
                public void UpdateReferences(Function dependantFunction, InterpreterTreeNode tree)
                {
                    DependantFunction = dependantFunction;

                    visitInterpreterTreeNode(tree);
                }
 /// <summary>
 /// Indicates if the node belongs to the search
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 private bool ShouldCheck(InterpreterTreeNode node)
 {
     return (Context == null) && (node.Start <= Position && Position <= node.End);
 }
예제 #15
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, Filter.AcceptableChoice expectation, bool lastElement)
        {
            ReturnValue retVal = new ReturnValue(this);

            if (instance == null)
            {
                // Special handling for THIS
                if (Image.CompareTo("THIS") == 0)
                {
                    INamable currentElem = Root;
                    while (currentElem != null)
                    {
                        Types.Type type = currentElem as Types.Type;
                        if (type != null)
                        {
                            Types.StateMachine stateMachine = type as Types.StateMachine;
                            while (stateMachine != null)
                            {
                                type         = stateMachine;
                                stateMachine = stateMachine.EnclosingStateMachine;
                            }
                            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, 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.getPredefinedItem(Image), expectation, 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)
                {
                    Utils.ISubDeclarator subDeclarator = currentNamable as Utils.ISubDeclarator;
                    if (subDeclarator != null && !(subDeclarator is Dictionary))
                    {
                        if (FillBySubdeclarator(subDeclarator, expectation, retVal) > 0 && lastElement)
                        {
                            return(retVal);
                        }
                    }

                    currentNamable = enclosingSubDeclarator(currentNamable);
                }

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

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

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

            return(retVal);
        }