//------< to find types defiend, functions and Complexity and size of functions >----- public static void doAnalysis(string[] files) { string filename = null; 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 { filename = file.ToString(); while (semi.getSemi()) { parser.parse(semi, filename); } // filename store with types and function to identify which types belongs to which file. } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); } }
//------< to find types defiend, functions and Complexity and size of functions >----- public static void doAnalysis(string[] files) { string filename = null; 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 { filename = file.ToString(); while (semi.getSemi()) parser.parse(semi, filename); // filename store with types and function to identify which types belongs to which file. } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); } }
//----< 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(); } }
/// <summary> /// This is the method where we create the code anlayser object. /// There will be only one code analyser object for all the files. /// It uses the parser module to find the relationship analysis. /// Once the results are generated, it will be stored in the centralised /// repo. We use this centralised repo from other module to know /// the type and dependency analysis. /// </summary> /// <param name="serverName"></param> public void analyze(string serverName) { Console.Write("\n CODE ANALYZER"); Console.Write("\n ======================\n"); CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; try { 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(); repo.CurrentFileName = file.ToString(); Elem elem = getDefaultElemData(file.ToString(), serverName); repo.locations.Add(elem); try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); } } catch (Exception) { Console.WriteLine("Error in the data. Exception thrown, pls check the input"); } }
//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(); } }
/* This method is used to call the relationship and complexity analysis * for each file in the input set */ public void analyze() { CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; /* These are the supported file formats in this tool. If input file is not in this format, * then analysis will not be done*/ string[] supportedFileFormatList = { ".cs", ".c", ".cpp", ".java", ".txt", ".bat" }; foreach (object file in files) { string fileExtension = Path.GetExtension(file.ToString()); bool supportedFileFormat = false; foreach (string currentFileExtension in supportedFileFormatList) { if (fileExtension == currentFileExtension) { supportedFileFormat = true; } } if (!supportedFileFormat) { Console.WriteLine("\nThe file {0} is of unsupported format", file.ToString()); continue; } if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); CodeAnalysis.Parser parser = builder.build(); Repository repo = Repository.getInstance(); Elem elem = getDefaultElemData(file.ToString()); repo.locations.Add(elem); try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); //Only when the user specifies the /R option, we do relationship analysis if (findRelationship) { semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } BuildCodeAnalyzerForRelationshipTypes builderreln = new BuildCodeAnalyzerForRelationshipTypes(semi); parser = builderreln.build(); try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } } semi.close(); } }
//----< 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(); } }