static void Main(string[] args) { Console.Write("\n Demonstrating TypeAnalysis"); Console.Write("\n ======================\n"); TypeAnalysis typeanalysis = new TypeAnalysis(); List <string> files = TestParser.ProcessCommandline(args); foreach (string file in files) { Console.Write("\n Processing file {0}\n", System.IO.Path.GetFileName(file)); ITokenCollection semi = Factory.create(); //semi.displayNewLines = false; if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", args[0]); return; } Console.Write("\n Type and Function Analysis"); Console.Write("\n ----------------------------"); BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); try { while (semi.get().Count > 0) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); List <Elem> table = rep.locations; File f = file.Substring(file.LastIndexOf('\\') + 1); string namesp = ""; foreach (Elem ele in table) { if (ele.type == "namespace") { namesp = ele.name; } typeanalysis.add(f, ele, namesp); } typeanalysis.display(); Console.Write("\n"); semi.close(); } Console.Write("\n\n"); }
//Generates the Type Table for all the different types that are used //in the given files static TypeTable makeTT(string[] args) { StringBuilder msg = new StringBuilder(); TypeTable tt = new TypeTable(); //Console.Write("\n Demonstrating Parser"); //Console.Write("\n ======================\n"); //ShowCommandLine(args); List <string> files = ProcessCommandline(args); foreach (string file in files) //loops through all the available files { //msg.Append(Environment.NewLine+" Processing file "+ System.IO.Path.GetFileName(file)); ITokenCollection semi = Factory.create(); //semi.displayNewLines = false; if (!semi.open(file as string)) { throw new Exception("\n Can't open file!\n\n"); } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); try { while (semi.get().Count > 0) //This is where the semi expressions { parser.parse(semi); //are getting parsed, above we had just defined the parser } //rememeber to remove the comment from the foreach in side parse } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); List <Elem> table = rep.locations; string[] fullname = file.Split('\\'); string filename = fullname[fullname.Length - 1]; foreach (var element in table) { //Console.WriteLine("Name: {0} Type: {1} Filename: {2}", element.name, element.type, filename); tt.add(element.type, filename, element.name); } //Display.showMetricsTable(table); semi.close(); } //Console.WriteLine("\n\n The TypeTable\n ============\n"); //tt.show(); //my TypeTable //Console.Write("\n\n"); return(tt); //Console.ReadKey(); }
//----< Test Stub >-------------------------------------------------- #if (TEST_PARSER) static void Main(string[] args) { Console.Write("\n Demonstrating Parser"); Console.Write("\n ======================\n"); ShowCommandLine(args); List <string> files = TestParser.ProcessCommandline(args); 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", args[0]); return; } Console.Write("\n Type and Function Analysis"); Console.Write("\n ----------------------------\n"); 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; foreach (Elem e in table) { Console.Write("\n {0,10}, {1,25}, {2,5}, {3,5}", e.type, e.name, e.begin, e.end); } Console.WriteLine(); Console.Write("\n\n That's all folks!\n\n"); semi.close(); Console.ReadLine(); } }
// get back the Tyeptable for other program using public TypeTable getTypeTable(string[] args) { TestParser tp = new TestParser(); TypeTable tt = new TypeTable(); string ns = ""; foreach (string file in args) { CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", args[0]); } 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(); List <Elem> table = rep.locations; foreach (Elem e in table) { if (e.type == "namespace") { ns = e.name; } if (e.type == "interface" || e.type == "class" || e.type == "struct" || e.type == "enum" || e.type == "delegate") { tt.add(e.name, Path.GetFileName(file), ns); } } semi.close(); } return(tt); }
/* * Method to parse through list of user input files and parse * for all user defined types */ public static void parseUserDefinedTypes(List <string> files) { if (files.Count == 0) { return; } foreach (String file in files) { Console.Write("Parsing for all user defined types"); 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.ToString()); } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); CodeAnalysis.Parser parser = builder.build(); //test against the detect class rule try { //use the existing parser to test rule while (semi.getSemi()) { int index = isClassExpression(semi); if (index != -1) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // local semiExp with tokens for type and name local.displayNewLines = false; local.Add(semi[index]).Add(semi[index + 1]); userDefinedSet.Add(semi[index + 1]); } } } catch (Exception ex) { Console.Write("\n\n {0}", ex.Message); } } // return userDefinedSet; }
//-------------<Build the Typetable for analysis>-------------------------- public void Testpre(string[] args) { Console.Write("\n\n Construct the TypeTable by semi and parser"); Console.Write("\n =========================================\n"); FindFile(args[0]); foreach (string file in files) { ITokenCollection semi = Factory.create(); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", args[0]); return; } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); try { while (semi.get().Count > 0) parser.parse(semi); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); table=rep.locations; File f = file.Substring(file.LastIndexOf('\\') + 1); string namesp = ""; foreach (Elem ele in table) { if (ele.type == "namespace") { namesp = ele.name; } typeana.add(f, ele, namesp); } semi.close(); } typeana.display(); }
//----< test if I can analyze all files in the solution >--------------------------------- public void type_analysis_test(string[] args) { Console.Write("\n Test for Type analysis:"); Console.Write("\n ==================================\n"); foreach (string file in args) { Console.Write("\n Processing file {0}\n", System.IO.Path.GetFileName(file)); ITokenCollection semi = Factory.create(); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", args[0]); return; } Console.Write("\n Type and Function Analysis"); Console.Write("\n ----------------------------"); BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); try { while (semi.get().Count > 0) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); List <Elem> table = rep.locations; Display.showMetricsTable(table); Console.Write("\n"); semi.close(); } Console.Write("\n\n"); }
//---------------< Requirement 5 >--------------------------------- public void TestReq5(string[] args) { Console.Write("\n Req 5 : \n Demostrate uesr-defined types"); Console.Write("\n ========================================\n"); foreach (string file in files) { ITokenCollection semi = Factory.create(); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", args[0]); return; } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); try { while (semi.get().Count > 0) parser.parse(semi); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); table = rep.locations; Console.Write("\n"); File f = file.Substring(file.LastIndexOf('\\') + 1); Console.Write("Processing file: " + f + "\n"); Display.showMetricsTable(table); semi.close(); } Console.Write("\n"); }
//----< Test Stub >-------------------------------------------------- #if(TEST_PARSER) static void Main(string[] args) { Console.Write("\n Demonstrating Parser"); Console.Write("\n ======================\n"); ShowCommandLine(args); List<string> files = TestParser.ProcessCommandline(args); 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", args[0]); return; } Console.Write("\n Type and Function Analysis"); Console.Write("\n ----------------------------\n"); 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; foreach (Elem e in table) { Console.Write("\n {0,10}, {1,25}, {2,5}, {3,5}", e.type, e.name, e.begin, e.end); } Console.WriteLine(); Console.Write("\n\n That's all folks!\n\n"); semi.close(); Console.ReadLine(); } }
/*----< define how each message will be processed >------------*/ void initializeDispatcher() { Func <CommMessage, CommMessage> getTopFiles = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["getTopFiles"] = getTopFiles; Func <CommMessage, CommMessage> getTopDirs = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["getTopDirs"] = getTopDirs; Func <CommMessage, CommMessage> moveIntoFolderFiles = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderFiles"] = moveIntoFolderFiles; Func <CommMessage, CommMessage> moveIntoFolderDirs = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs; Func <CommMessage, CommMessage> analyzeFiles = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "analyzeFiles"; TypeAnalysis typeana = new TypeAnalysis(); DepAnalys depana = new DepAnalys(); StrongComp strongcomp = new StrongComp(); List <Elem> table = new List <Elem>(); foreach (string file in msg.arguments) { ITokenCollection semi = Factory.create(); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return(null); } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); try { while (semi.get().Count > 0) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); table = rep.locations; File f = file.Substring(file.LastIndexOf('\\') + 1); string namesp = ""; foreach (Elem ele in table) { if (ele.type == "namespace") { namesp = ele.name; } typeana.add(f, ele, namesp); } semi.close(); } depana.BuildGraph(msg.arguments); foreach (string f in msg.arguments) { depana.ConnectNode(typeana, f); } //move to reply.arguments[0]; foreach (CsNode <string, string> node in depana.csgraph.adjList) { StringBuilder temp = new StringBuilder(); temp.Append(node.name.Substring(node.name.LastIndexOf('/') + 1)); temp.Append(" \n Dependency : ["); foreach (CsEdge <string, string> edge in node.children) { temp.Append(edge.targetNode.name.Substring(edge.targetNode.name.LastIndexOf('/') + 1)); temp.Append(" "); } temp.Append(" ] \n"); reply.arguments.Add(temp.ToString()); } strongcomp.FindConnect(depana.csgraph); //move to reply.arguments[1]; int i = 1; foreach (List <CsNode <string, string> > nodes in strongcomp.result) { StringBuilder temp = new StringBuilder(); temp.Append("Components " + i.ToString() + ": "); foreach (CsNode <string, string> node in nodes) { temp.Append(node.name.Substring(node.name.LastIndexOf('/') + 1) + " "); } temp.Append("\n"); i++; reply.arguments.Add(temp.ToString()); } return(reply); }; messageDispatcher["analyzeFiles"] = analyzeFiles; Func <CommMessage, CommMessage> demo456 = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "demo456"; reply.arguments.Add(""); return(reply); }; messageDispatcher["demo456"] = demo456; }
//read the list of files, one by one and calls BuildCodeAnalyzer and parser functions public void analyze() { Console.Write("\n CODE ANALYZER"); Console.Write("\n ======================\n"); CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; foreach (object file in files) { Console.Write("\n\n Processing file {0}\n", file as string); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } Console.Write("\n Type and Function Analysis"); Console.Write("\n ----------------------------\n"); BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); CodeAnalysis.Parser parser = builder.build(); try { while (semi.getSemi()) parser.parse(semi); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); if (relationshipflag) { semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } BuildCodeAnalyzerRelationships builderreln = new BuildCodeAnalyzerRelationships(semi); parser = builderreln.build(); try { while (semi.getSemi()) parser.parse(semi); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } } semi.close(); } }
static void Main(string[] args) { List <string> CSharpFiles = Ingest.GenerateFileStructure(args); List <string> contentList = new List <string>(); foreach (string file in CSharpFiles) { Console.Write("\n Processing file {0}\n", System.IO.Path.GetFileName(file)); CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; if (!semi.open(file)) { Console.Write("\n Can't open {0}\n\n", args[0]); return; } Console.Write("\n Type and Function Analysis"); Console.Write("\n ----------------------------"); BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); try { while (semi.getSemi()) { parser.parse(semi); } Console.Write("\n locations table contains:"); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); List <Elem> table = rep.locations; Console.Write( "\n {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}", "category", "name", "bLine", "eLine", "bScop", "eScop", "size", "cmplx" ); Console.Write( "\n {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}", "--------", "----", "-----", "-----", "-----", "-----", "----", "-----" ); List <string> functionList = new List <string>(); foreach (Elem e in table) { if (e.type == "class" || e.type == "struct" || e.type == "Comment") { Console.Write("\n"); } Console.Write("\n {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}", e.type, e.name, e.beginLine, e.endLine, e.beginScopeCount, e.endScopeCount + 1, e.endLine - e.beginLine + 1, e.endScopeCount - e.beginScopeCount + 1 ); if (e.type == "function") { contentList = PostProcessor.getContentBetweenLines(file, e.beginLine, e.endLine); functionList.Add(e.name); } if (e.type == "class" || e.type == "namespace") { PostProcessor.addObjectToFile(e.name, file); } HTML_Builder.buildFileStructure(file, e.type, e.name, e.beginLine, e.endLine, contentList); } PostProcessor.addFileToFileList(functionList, file); Console.Write("\n"); semi.close(); } PostProcessor.buildDependencies(CSharpFiles); HTML_Builder.generateFileList(CSharpFiles); foreach (string file in CSharpFiles) { HTML_Builder.buildPageContent(file.Substring(file.LastIndexOf("\\") + 1), CSharpFiles); } Console.Write("\n\n"); }
static void Main(string[] args) { Console.WriteLine("Path containing all the test files : TestFiles\\.."); Console.WriteLine("Enter the directory of test files"); string file_path = Console.ReadLine(); List <String> files = new List <String>(); files = DirSearch(file_path); Console.Write("This project contains 13 packages demonstrating requirement 3:\n"); Console.Write("1) DemoExecutive\n"); Console.Write("2) DemoReqs\n"); Console.Write("3) DependencyAnalysis\n"); Console.Write("4) Display\n"); Console.Write("5) Element\n"); Console.Write("6) FileMgr\n"); Console.Write("7) Parser\n"); Console.Write("8) SemiExp\n"); Console.Write("9) StrongComponent\n"); Console.Write("10) TestHarness\n"); Console.Write("11) Toker\n"); Console.Write("12) TypeTable\n"); Console.Write("13) AutomatedTestUnit\n"); Console.Write("\n ======================\n"); Console.Write("\n Demonstrating Parser"); Console.Write("\n ======================\n"); //ShowCommandLine(args); //List<string> files = ProcessCommandline(args); DepAnalysis da = new DepAnalysis(); foreach (string file in files) { Console.Write("\n Processing file {0}\n", System.IO.Path.GetFileName(file)); ITokenCollection semi = Factory.create(); //semi.displayNewLines = false; if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", args[0]); return; } Console.Write("\n Type and Function Analysis"); Console.Write("\n ----------------------------"); BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); try { while (semi.get().Count > 0) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); List <Elem> table = rep.locations; TypeTable.TypeTable tt = new TypeTable.TypeTable(); ///shows typetable foreach (Elem e in table) { tt.add(e.type, e.name); if (e.type == "using") { da.add(System.IO.Path.GetFileName(file), e.name); } } tt.show(); //Console.Write("\n ----------------------------"); Console.WriteLine("\nShowing TypeTables of files demonstrating requirement 5:\n"); //Console.Write("\n ----------------------------"); Console.Write("\n TypeTable contains types: "); foreach (var elem in tt.table) { Console.Write("{0} ", elem.Key); } ////Display.showMetricsTable(table); Console.Write("\n"); semi.close(); } var nodes = new List <CsNode <string, string> >(); foreach (var elem in da.table) { nodes.Add(new CsNode <string, string>(elem.Key)); //Console.Write("\n {0} depends on", elem.Key); } nodes.ToArray(); //foreach (var elem in da.table) //{ // foreach (var item in elem.Value) // { // //nodes[IndexOf(elem.Key)].addChild(nodes[IndexOf(item.file)], "edge" + elem.Key + " " + item.file); // //nodes[0].addChild(item.file, "edge" + elem.Key + " " + item.file); // //nodes[nodes.IndexOf(elem.Value)].addChild(nodes[nodes.IndexOf(item.file)], "edge" + elem.Key + " " + item.file); // Console.Write("\n {0}.cs", item.file); // } //} //iterate through list of list elements of a file //da.table --gets table, for (int i = 0; i < da.table.Count; i++) { var item = da.table.ElementAt(i); for (int j = 0; j < item.Value.Count; j++) { //Console.WriteLine(i+"^"+ da.table.Values); nodes[i].addChild(nodes[j], "edge" + i + j); } } Graph <string, string> graph = new Graph <string, string>("Fred"); for (int i = 0; i < da.table.Count; i++) { graph.addNode(nodes[i]); } graph.startNode = nodes[0]; //Console.WriteLine("\n Showing graph walk starting at node[0]\n"); //Console.Write("\n\n starting walk at {0}", graph.startNode.name); //Console.Write("\n not showing backtracks"); //graph.walk(); Console.Write("\n ----------------------------"); Console.WriteLine("\nShowing dependencies between files demonstrating requrement 4:\n\n"); Console.Write("\n ----------------------------"); //shows dependency analysis da.show(); Console.Write("\n\n"); Console.Write("\n ----------------------------"); Console.Write("\nShowing all strong components, if any, in the file collection, based on the dependency analysis demonstrating requirement 6:\n\n"); Console.Write("\n ----------------------------"); graph.startNode = nodes[0]; graph.Tarjan(); Console.Write("\n\n"); Console.Write("\n ----------------------------"); Console.WriteLine("\nThis demo executive file demonstrates all the outputs and is well formatted as per requirement 7 and 8\n"); Console.Write("\n ----------------------------"); Console.ReadLine(); }
//read the list of files, one by one and calls BuildCodeAnalyzer and parser functions public void analyze(string serverName) { Console.Write("\n CODE ANALYZER"); Console.Write("\n ======================\n"); CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; foreach (object file in files) { Console.Write("\n\n Processing file {0}\n", file as string); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } Console.Write("\n Type and Function Analysis"); Console.Write("\n ----------------------------\n"); BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); CodeAnalysis.Parser parser = builder.build(); Repository repo = Repository.getInstance(); Elem elem = getDefaultElemData(file.ToString(), serverName); repo.analyzedata.Add(elem); try { while (semi.getSemi()) parser.parse(semi); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); } }