Beispiel #1
0
 private void CreateLibraryEntry(LibraryNode parent, CocoParserProxy.CocoParseResult result, ModuleId moduleId)
 {
     CreateLibraryEntry(parent, moduleId, result.CharSets, result.References);
     CreateLibraryEntry(parent, moduleId, result.Tokens, result.References);
     CreateLibraryEntry(parent, moduleId, result.Productions, result.References);
 }
Beispiel #2
0
        /// <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>
        private 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 (0 != requests.Count)
                    {
                        task = requests.Dequeue();
                    }
                    if (0 == requests.Count)
                    {
                        requestPresent.Reset();
                    }
                }
                if (null == task)
                {
                    continue;
                }

                string sourceText = task.Text;
                if (sourceText == null)
                {
                    //should not happen, but to be robust
                    if (!System.IO.File.Exists(task.FileName))
                    {
                        continue;
                    }

                    //read file content as string
                    try {
                        using (System.IO.StreamReader sr = System.IO.File.OpenText(task.FileName)) {
                            sourceText = sr.ReadToEnd();
                        }
                    }
                    catch (Exception ex) {
                        System.Diagnostics.Trace.WriteLine(String.Format("Error when parsing file '{0}': {1}\n{2}", task.FileName, ex.Message, ex.StackTrace));
                        continue;
                    }
                }

                if (string.IsNullOrEmpty(sourceText))
                {
                    continue;
                }

                CocoParserProxy.CocoParseResult result = CocoParserProxy.Parse(sourceText, task.FileName);

                //maybe use coco-library entry (to avoid not-implemented exception in librarynode.getcategory2)
                CocoLibraryNode module = new CocoLibraryNode(
                    System.IO.Path.GetFileName(task.FileName),
                    1,
                    1,
                    1,
                    task.ModuleID.Hierarchy,
                    task.ModuleID.ItemID,
                    LibraryNode.LibraryNodeType.Classes);


                CreateLibraryEntry(module, result, task.ModuleID);

                if (null != task.ModuleID)
                {
                    LibraryNode previousItem = null;
                    lock (files) {
                        if (files.TryGetValue(task.ModuleID, out previousItem))
                        {
                            files.Remove(task.ModuleID);
                        }
                    }
                    library.RemoveNode(previousItem);
                }
                library.AddNode(module);
                if (null != task.ModuleID)
                {
                    lock (files) {
                        files.Add(task.ModuleID, module);
                    }
                }
            }
        }