示例#1
0
 private static void ExtractFunctions(KeyValuePair<string, XmlDocument> parsedFile)
 {
     var traverser = new XmlTraverser ();
     var extractor = new ClassAndFunctionExtractor ();
     traverser.AddVisitor (extractor);
     traverser.Traverse (parsedFile.Value.FirstChild.NextSibling);
     FunctionsHandler.Instance.CustomFunctions.AddRange (extractor.Functions);
     foreach (var @class in extractor.Classes) {
         foreach (var method in @class.Methods) {
             //HACK: This is not a good way to handle this! Should we add a new derived function class called method that includes the class name
             //-||-: and make a special list for them in the function handler, or is this okay?
             method.Name = @class.Name + "->" + method.Name;
             FunctionsHandler.Instance.CustomFunctions.Add (method);
         }
     }
 }
示例#2
0
        private static File BuildFileCFGAndExtractFileInformation(KeyValuePair<string, XmlDocument> parsedFile)
        {
            var traverser = new XmlTraverser ();
            var metricAnalyzer = new MetricVisitor ();
            var extractor = new ClassAndFunctionExtractor ();
            var printer = new ASTPrinter (Console.Out);
            var cfgcreator = new SuperCFGCreator ();

            traverser.AddVisitor (extractor);
            traverser.AddVisitor (metricAnalyzer);

            traverser.Traverse (parsedFile.Value.FirstChild.NextSibling);
            cfgcreator.Traverse (parsedFile.Value.FirstChild.NextSibling);

            var ctlPrep = new CFGCTLPreparation ();
            ctlPrep.AddSelfLoops (cfgcreator.Graph);

            File file = new File (parsedFile.Value) {
                CFG = cfgcreator.Graph,
                FullPath = parsedFile.Key,
                Interfaces = extractor.Interfaces.GroupBy (i => i.Name, i => i).ToDictionary (i => i.Key, i => i.ToList ()),
                Classes = extractor.Classes.GroupBy (c => c.Name, c => c).ToDictionary (c => c.Key, c => c.ToList ()),
                Closures = extractor.Closures.ToArray (),
                Functions = extractor.Functions.GroupBy (i => i.Name, i => i).ToDictionary (i => i.Key, i => i.ToList ())
            };
            return file;
        }
示例#3
0
        private static File BuildFileCFGAndExtractFileInformation(KeyValuePair<string, XmlDocument> parsedFile)
        {
            var traverser = new XmlTraverser();
            var metricAnalyzer = new MetricVisitor();
            var extractor = new ClassAndFunctionExtractor();
            var printer = new ASTPrinter(Console.Out);
            var cfgcreator = new CFGCreator();
            traverser.AddVisitor(extractor);
            traverser.AddVisitor(metricAnalyzer);
            traverser.AddVisitor(cfgcreator);
            //traverser.AddVisitor(printer);
            traverser.AddVisitors(_components.AstVisitors.ToArray());

            traverser.Traverse(parsedFile.Value.FirstChild.NextSibling);

            foreach (var function in extractor.Functions)
            {
                function.File = parsedFile.Key;
            }
            foreach (var closure in extractor.Closures)
            {
                closure.File = parsedFile.Key;
            }

            FunctionsHandler.Instance.CustomFunctions.AddRange(extractor.Functions);

            foreach (var @class in extractor.Classes)
            {
                @class.File = parsedFile.Key;
                foreach (var method in @class.Methods)
                {
                    //HACK: This is not a good way to handle this! Should we add a new derived function class called method that includes the class name
                    //-||-: and make a special list for them in the function handler, or is this okay?
                    method.Name = @class.Name + "->" + method.Name;
                    method.File = parsedFile.Key;
                    FunctionsHandler.Instance.CustomFunctions.Add(method);
                }
            }

            //cfgcreator.Graph.VisualizeGraph("graph", Program.Configuration.GraphSettings);
            var cfgPruner = new CFGPruner();
            cfgPruner.Prune(cfgcreator.Graph);
            //cfgcreator.Graph.VisualizeGraph("graph-pruned", Configuration.GraphSettings);

            File file = new File(parsedFile.Value) {
                                                       CFG = cfgcreator.Graph,
                                                       FullPath = parsedFile.Key,
                                                       Interfaces = extractor.Interfaces.GroupBy(i => i.Name, i => i).ToDictionary(i => i.Key, i => i.ToList()),
                                                       Classes = extractor.Classes.GroupBy(c => c.Name, c => c).ToDictionary(c => c.Key, c => c.ToList()),
                                                       Closures = extractor.Closures.ToArray(),
                                                       Functions = extractor.Functions.GroupBy(i => i.Name, i => i).ToDictionary(i => i.Key, i => i.ToList())
                                                   };
            return file;
        }