Example #1
0
        //public virtual Location Start
        //{
        //  get
        //  {
        //    return Location.None;
        //  }
        //}
        //public virtual Location End
        //{
        //  get
        //  {
        //    return Location.None;
        //  }
        //}
        public void Add(ScopeNode node)
        {
            if (_nested == null)
                _nested = new List<ScopeNode>();

            _nested.Add(node);
        }
Example #2
0
        //public virtual Location Start
        //{
        //  get
        //  {
        //	return Location.None;
        //  }
        //}
        //public virtual Location End
        //{
        //  get
        //  {
        //	return Location.None;
        //  }
        //}

        public void Add(ScopeNode node)
        {
            if (_nested == null)
            {
                _nested = new List <ScopeNode>();
            }

            _nested.Add(node);
        }
Example #3
0
        internal NemerleLibraryNode(
            ScopeNode scope,
            string namePrefix,
            IVsHierarchy hierarchy,
            uint itemId)
            : base(scope.Name)
        {
            _sourceSpan = new TextSpan();

            //if (scope is FunctionNode)
            //{
            //  this.NodeType = LibraryNodeType.Members;
            //}
            //else if (scope is ClassNode)
            //{
            //  this.NodeType = LibraryNodeType.Classes;
            //  this.Name = string.Format(CultureInfo.InvariantCulture, "{0}{1}", namePrefix, scope.Name);
            //}

            //this.ownerHierarchy = hierarchy;
            //this.fileId = itemId;

            //// Now check if we have all the information to navigate to the source location.
            //if ((null != ownerHierarchy) && (VSConstants.VSITEMID_NIL != fileId))
            //{
            //  if ((0 != Location.Compare(Location.None, scope.Start)) && (0 != Location.Compare(Location.None, scope.End)))
            //  {
            //	sourceSpan = new TextSpan();
            //	sourceSpan.iStartIndex = scope.Start.column;
            //	if (scope.Start.line > 0)
            //	{
            //	  sourceSpan.iStartLine = scope.Start.line - 1;
            //	}
            //	sourceSpan.iEndIndex = scope.End.column;
            //	if (scope.End.line > 0)
            //	{
            //	  sourceSpan.iEndLine = scope.End.line - 1;
            //	}
            //	this.CanGoToSource = true;
            //  }
            //}

            throw new NotImplementedException();
        }
Example #4
0
        internal NemerleLibraryNode(
            ScopeNode	scope,
            string	   namePrefix,
            IVsHierarchy hierarchy,
            uint		 itemId)
            : base(scope.Name)
        {
            _sourceSpan = new TextSpan();

            //if (scope is FunctionNode)
            //{
            //  this.NodeType = LibraryNodeType.Members;
            //}
            //else if (scope is ClassNode)
            //{
            //  this.NodeType = LibraryNodeType.Classes;
            //  this.Name = string.Format(CultureInfo.InvariantCulture, "{0}{1}", namePrefix, scope.Name);
            //}

            //this.ownerHierarchy = hierarchy;
            //this.fileId = itemId;

            //// Now check if we have all the information to navigate to the source location.
            //if ((null != ownerHierarchy) && (VSConstants.VSITEMID_NIL != fileId))
            //{
            //  if ((0 != Location.Compare(Location.None, scope.Start)) && (0 != Location.Compare(Location.None, scope.End)))
            //  {
            //	sourceSpan = new TextSpan();
            //	sourceSpan.iStartIndex = scope.Start.column;
            //	if (scope.Start.line > 0)
            //	{
            //	  sourceSpan.iStartLine = scope.Start.line - 1;
            //	}
            //	sourceSpan.iEndIndex = scope.End.column;
            //	if (scope.End.line > 0)
            //	{
            //	  sourceSpan.iEndLine = scope.End.line - 1;
            //	}
            //	this.CanGoToSource = true;
            //  }
            //}

            throw new NotImplementedException();
        }
        void CreateModuleTree(
            LibraryNode root,
            LibraryNode current,
            ScopeNode scope,
            string namePrefix,
            ModuleID moduleId)
        {
            if ((null == root) || (null == scope) || (null == scope.NestedScopes))
            {
                return;
            }

            foreach (ScopeNode subItem in scope.NestedScopes)
            {
                NemerleLibraryNode newNode = new NemerleLibraryNode(
                    subItem, namePrefix, moduleId.Hierarchy, moduleId.ItemID);

                string newNamePrefix = namePrefix;

                // The classes are always added to the root node, the functions to the current node.
                //
                if ((newNode.NodeType & LibraryNode.LibraryNodeType.Members) != LibraryNode.LibraryNodeType.None)
                {
                    current.AddNode(newNode);
                }
                else if ((newNode.NodeType & LibraryNode.LibraryNodeType.Classes) != LibraryNode.LibraryNodeType.None)
                {
                    // Classes are always added to the root.
                    //
                    root.AddNode(newNode);
                    newNamePrefix = newNode.Name + ".";
                }

                // Now use recursion to get the other types.
                //
                CreateModuleTree(root, newNode, subItem, newNamePrefix, moduleId);
            }
        }
Example #6
0
        void CreateModuleTree(
            LibraryNode root,
            LibraryNode current,
            ScopeNode   scope,
            string	  namePrefix,
            ModuleID	moduleId)
        {
            if ((null == root) || (null == scope) || (null == scope.NestedScopes))
                return;

            foreach (ScopeNode subItem in scope.NestedScopes)
            {
                NemerleLibraryNode newNode = new NemerleLibraryNode(
                    subItem, namePrefix, moduleId.Hierarchy, moduleId.ItemID);

                string newNamePrefix = namePrefix;

                // The classes are always added to the root node, the functions to the current node.
                //
                if ((newNode.NodeType & LibraryNode.LibraryNodeType.Members) != LibraryNode.LibraryNodeType.None)
                {
                    current.AddNode(newNode);
                }
                else if ((newNode.NodeType & LibraryNode.LibraryNodeType.Classes) != LibraryNode.LibraryNodeType.None)
                {
                    // Classes are always added to the root.
                    //
                    root.AddNode(newNode);
                    newNamePrefix = newNode.Name + ".";
                }

                // Now use recursion to get the other types.
                //
                CreateModuleTree(root, newNode, subItem, newNamePrefix, moduleId);
            }
        }
        /// <summary>
        /// Main function of the parsing thread.
        /// This function waits on the queue of the parsing requests and build
        /// the parsing tree for a specific file. The resulting tree is built
        /// using LibraryNode objects so that it can be used inside the class
        /// view or object browser.
        /// </summary>
        void ParseThread()
        {
            const int waitTimeout = 500;

            // Define the array of events this function is interest in.
            //
            WaitHandle[] eventsToWait = new WaitHandle[] { _requestPresent, _shutDownStarted };

            // Execute the tasks.
            //
            while (true)
            {
                // Wait for a task or a shutdown request.
                //
                int waitResult = WaitHandle.WaitAny(eventsToWait, waitTimeout, false);

                if (1 == waitResult)
                {
                    // The shutdown of this component is started, so exit the thread.
                    return;
                }

                LibraryTask task = null;

                lock (_requests)
                {
                    if (_requests.Count != 0)
                    {
                        task = _requests.Dequeue();
                    }

                    if (_requests.Count == 0)
                    {
                        _requestPresent.Reset();
                    }
                }

                if (null == task)
                {
                    continue;
                }

                ScopeNode scope = null;

                if (task.Text == null)
                {
                    if (File.Exists(task.FileName))
                    {
                        Debug.WriteLine("Parse request (no text): " + task.FileName + " " + task.ModuleID);
                        return;
                    }
                }
                else
                {
                    Debug.WriteLine("Parse request: " + task.FileName + " " + task.ModuleID);
                    return;
                }

                LibraryNode module = new LibraryNode(
                    Path.GetFileName(task.FileName),
                    LibraryNode.LibraryNodeType.PhysicalContainer);

                CreateModuleTree(module, module, scope, "", task.ModuleID);

                if (task.ModuleID != null)
                {
                    LibraryNode previousItem;

                    lock (_files)
                        if (_files.TryGetValue(task.ModuleID, out previousItem))
                        {
                            _files.Remove(task.ModuleID);
                        }

                    _library.RemoveNode(previousItem);
                }

                _library.AddNode(module);

                if (task.ModuleID != null)
                {
                    lock (_files)
                        _files.Add(task.ModuleID, module);
                }
            }
        }