static void doAnalysis(string[] files, bool relation_flag, bool xml_flag) { List<Elem> TABLE = new List<Elem>(); foreach (object file in files) { CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); try { while (semi.getSemi()) parser.parse(semi); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); TABLE.AddRange(rep.locations); // Build a TABLE to store all the elements, provided to be searched for relationshipAnalysis class semi.close(); } Console.Write("\n Demonstrating Parser"); Console.Write("\n ======================\n"); // parse all files and store the elements into table for each file foreach (object file in files) { Console.Write("\n Processing file {0}\n", file as string); CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); try { while (semi.getSemi()) parser.parse(semi); Console.Write("\n\n locations table contains:"); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); List<Elem> table = rep.locations; // display basic information for elements including size and complexity Console.Write("\n type name begin end size complexity"); foreach (Elem e in table) { if (e.type == "function") { ComplexityAnalysis ca = new ComplexityAnalysis(); e.complexity = ca.ComplexityAnalyze(e, file); } Console.Write("\n {0,9}, {1,20}, {2,8}, {3,8}, {4,8}, {5,8}", e.type, e.name, e.begin, e.end, e.end - e.begin + 1, e.complexity); } //display the relationships between classes if (relation_flag == true) { foreach (Elem e in table) { e.AggregationFlag = false; e.CompositionFlag = false; e.UsingFlag = false; if (e.type == "class" || e.type == "struct" || e.type == "interface") { Console.Write("\n\n {0} {1}", e.type, e.name); Console.Write("------------------------------------------------------\n"); RelationshipAnalysis ra = new RelationshipAnalysis(); ra.RelationshipAnalyzer(e, file, TABLE); foreach (Elem ele in TABLE) { ele.AggregationFlag = false; ele.CompositionFlag = false; ele.UsingFlag = false; } } } } Console.WriteLine(); //display xml files for each file if (xml_flag == true) { XML x = new XML(); x.XmlBuilder(table, (string)file); } } Console.Write("\n"); DisplaySummary(TABLE); }
static void Main(string[] args) { Console.Write("\n Testing XML - XmlBuilder "); Console.Write("\n ============================\n"); List<Elem> test = new List<Elem>(); Elem ns = new Elem(); ns.name = "testNameSpace"; ns.type = "namespace"; ns.begin = 10; ns.end = 100; Elem cl = new Elem(); cl.name = "testClass"; cl.type = "class"; cl.begin = 20; cl.end = 80; Elem func = new Elem(); func.name = "testFunction"; func.type = "function"; func.begin = 30; func.end = 60; test.Add(ns); test.Add(cl); test.Add(func); XML xb = new XML(); xb.XmlBuilder(test); }