Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new srcML location object
 /// </summary>
 /// <param name="element">The srcML element that this location refers to</param>
 /// <param name="fileUnit">The file unit that contains
 /// <paramref name="element"/></param>
 /// <param name="isReferenceLocation">true if this is a reference location; false
 /// otherwise</param>
 public SrcMLLocation(XElement element, XElement fileUnit, bool isReferenceLocation)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (fileUnit == null)
     {
         throw new ArgumentNullException("fileUnit");
     }
     this.SourceFileName       = SrcMLElement.GetFileNameForUnit(fileUnit);
     this.StartingLineNumber   = element.GetSrcLineNumber();
     this.StartingColumnNumber = element.GetSrcLinePosition();
     this.XPath       = element.GetXPath();
     this.IsReference = isReferenceLocation;
     SetEndingLocation(element);
 }
Ejemplo n.º 2
0
 private void ReadArchive()
 {
     if (null != Archive)
     {
         scopeLock.EnterWriteLock();
         try {
             foreach (var unit in Archive.FileUnits)
             {
                 try {
                     string fileName = SrcMLElement.GetFileNameForUnit(unit);
                     AddFile(unit);
                     OnFileProcessed(new FileEventRaisedArgs(FileEventType.FileAdded, fileName));
                 } catch (Exception ex) {
                     OnErrorRaised(new ErrorRaisedArgs(ex));
                 }
             }
         } finally {
             scopeLock.ExitWriteLock();
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates SWUMs for the method definitions within the given SrcML file
        /// </summary>
        /// <param name="fileUnit">A SrcML file unit.</param>
        public void AddSrcMLFile(XElement fileUnit)
        {
            var fileName = SrcMLElement.GetFileNameForUnit(fileUnit);

            AddSwumForMethodDefinitions(fileUnit, fileName);
        }
Ejemplo n.º 4
0
        private static void GenerateData(string sourcePath, string dataPath, string csvDirectory)
        {
            Dictionary <Language, ICodeParser> CodeParser = new Dictionary <Language, ICodeParser>()
            {
                { Language.CPlusPlus, new CPlusPlusCodeParser() },
                { Language.Java, new JavaCodeParser() },
                { Language.CSharp, new CSharpCodeParser() }
            };

            string fileLogPath = Path.Combine(dataPath, "parse.log");
            string callLogPath = Path.Combine(dataPath, "methodcalls.log");
            string csvPath     = Path.Combine(csvDirectory, "timing.csv");
            string jsonPath    = String.Format("{0}.json", Path.Combine(@"c:\Workspace\DataVisualization", dataPath.Substring(23)));

            if (!Directory.Exists(sourcePath))
            {
                Console.Error.WriteLine("{0} does not exist", sourcePath);
                return;
            }

            if (File.Exists(callLogPath))
            {
                File.Delete(callLogPath);
            }
            if (File.Exists(fileLogPath))
            {
                File.Delete(fileLogPath);
            }

            var archive = new SrcMLArchive(dataPath);

            archive.XmlGenerator.ExtensionMapping[".cxx"] = Language.CPlusPlus;
            archive.XmlGenerator.ExtensionMapping[".c"]   = Language.CPlusPlus;
            archive.XmlGenerator.ExtensionMapping[".cc"]  = Language.CPlusPlus;
            archive.XmlGenerator.ExtensionMapping[".hpp"] = Language.CPlusPlus;

            AbstractFileMonitor monitor = new FileSystemFolderMonitor(sourcePath, dataPath, new LastModifiedArchive(dataPath), archive);

            ManualResetEvent mre              = new ManualResetEvent(false);
            Stopwatch        timer            = new Stopwatch();
            bool             startupCompleted = false;

            monitor.UpdateArchivesCompleted += (o, e) => {
                timer.Stop();
                startupCompleted = true;
                mre.Set();
            };

            timer.Start();
            var task = monitor.UpdateArchivesAsync();

            string[] spinner       = new string[] { "\\\r", "|\r", "/\r" };
            int      spinner_index = -1;

            while (!startupCompleted)
            {
                spinner_index = (++spinner_index) % 3;
                Console.Write("Updating archive for {0}... {1}", sourcePath, spinner[spinner_index]);
                startupCompleted = mre.WaitOne(5000);
            }
            timer.Stop();
            Console.WriteLine("Updating archive for {0}... {1}", sourcePath, timer.Elapsed);

            IScope globalScope = null;

            timer.Reset();

            int numberOfFailures  = 0;
            int numberOfSuccesses = 0;
            int numberOfFiles     = 0;
            Dictionary <string, List <string> > errors = new Dictionary <string, List <string> >();

            if (!File.Exists(csvPath))
            {
                File.WriteAllLines(csvPath, new string[] { String.Join(",", "Project", "Files", "Failures", "Time (s)") });
            }
            using (StreamWriter fileLog = new StreamWriter(fileLogPath), csvFile = new StreamWriter(csvPath, true)) {
                timer.Start();
                foreach (var unit in archive.FileUnits)
                {
                    var fileName = SrcMLElement.GetFileNameForUnit(unit);
                    var language = SrcMLElement.GetLanguageForUnit(unit);

                    try {
                        var scopeForUnit = CodeParser[language].ParseFileUnit(unit);

                        if (null == globalScope)
                        {
                            globalScope = scopeForUnit;
                        }
                        else
                        {
                            globalScope = globalScope.Merge(scopeForUnit);
                        }
                        timer.Stop();
                        fileLog.WriteLine("Parsing {0} PASSED", fileName);
                        numberOfSuccesses++;
                    } catch (Exception e) {
                        timer.Stop();
                        fileLog.WriteLine("Parsing {0} FAILED", fileName);
                        fileLog.WriteLine(e.StackTrace);
                        var key = e.StackTrace.Split('\n')[0].Trim();
                        if (!errors.ContainsKey(key))
                        {
                            errors[key] = new List <string>();
                        }
                        errors[key].Add(fileName);

                        numberOfFailures++;
                    } finally {
                        if (++numberOfFiles % 50 == 0)
                        {
                            Console.Write("{0,5:N0} files completed in {1} with {2,5:N0} failures\r", numberOfFiles, timer.Elapsed, numberOfFailures);
                            csvFile.WriteLine(string.Join(",", sourcePath, numberOfFiles, numberOfFailures, timer.Elapsed.TotalSeconds));
                        }
                        timer.Start();
                    }
                }
            }
            timer.Stop();
            Console.WriteLine("{0,5:N0} files completed in {1} with {2,5:N0} failures", numberOfFiles, timer.Elapsed, numberOfFailures);

            Console.WriteLine("\nSummary");
            Console.WriteLine("===================");

            Console.WriteLine("{0,10:N0} failures  ({1,8:P2})", numberOfFailures, ((float)numberOfFailures) / numberOfFiles);
            Console.WriteLine("{0,10:N0} successes ({1,8:P2})", numberOfSuccesses, ((float)numberOfSuccesses) / numberOfFiles);
            Console.WriteLine("{0} to generate data", timer.Elapsed);
            Console.WriteLine("See parse log at {0}", fileLogPath);

            OutputCallGraphByType(globalScope, jsonPath);

            PrintScopeReport(globalScope, sourcePath, csvDirectory);
            PrintMethodCallReport(globalScope, sourcePath, csvDirectory, callLogPath);
        }