//----------<parse1 starts here, it identifies all the types>----------------- public void doAnalysis(string[] files) { foreach (object file in files) { string filename = Convert.ToString(file); 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, filename); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); List<Elem> table = rep.locations; //storing the repository data into a List semi.close(); } }
// ------------< to find Relationship between types defiend >-------------- public static void doRelationAnalysis(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; } BuildCodeAnalyzerRelation builder = new BuildCodeAnalyzerRelation(semi); Parser parser = builder.build(); try { filename = file.ToString(); while (semi.getSemi()) parser.parse(semi, filename); } 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(); typetable= RepositoryForOutput.storageForOutput_; } }
// function that parse all the files and build a inquiry table static void doAnalysis(string[] files, bool relation, bool xml) { List<Elem> fileSetInfo = new List<Elem>(); // store type and name of file set, use for relationship analysis List<Elem> summaryTAB = new List<Elem>(); // store size and complexity, use for display summary of the whole file set 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); // creat a repository Parser parser = builder.build(); // creat a parser object and five rule object, attach the rules to parser try { while (semi.getSemi()) parser.parse(semi); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); fileSetInfo.AddRange(rep.locations); // push all elements in current file into inquiry table semi.close(); } secondAnalysis(files, fileSetInfo, summaryTAB, relation, xml); }
static public void doAnalysis(string[] files) { int skipCount = 0; CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); Repository rep = Repository.getInstance(); List<Elem> fileSetInfo = new List<Elem>(); // store type and name of file set, use for relationship analysis foreach (string file in files) { if(Display.showFiles) Display.displayString(""); Display.displayFiles(act, "Processing file: " + file); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } foreach (Elem e in rep.locations) { e.filename = file; } List<Elem> table = rep.locations; if (table.Count == 0) { ++skipCount; continue; } fileSetInfo.AddRange(rep.locations); // push all elements in current file into inquiry table semi.close(); rep.LocationsTable[file] = table; // Obtained all the types and names of the file set, locationTable is actually a inquiry table rep.locations = new List<Elem>(); } doAnalysis_Again(fileSetInfo, files); displaySkipped(skipCount); //displayAnalysis(rep); //analysisSummary(rep); }
public override void doAction(CSsemi.CSemiExp semi) { Repository_types reporel_ = Repository_types.getInstance(); //************************checks for inheritance*********************** if (semi.Contains("inheritance") != -1) { int loc = semi.Contains("inheritance"); if (loc != -1) { Elem e = new Elem(); e.type = semi[loc + 3]; e.name = semi[loc + 1]; repo_.stack.push(e); relationelem r_elem = new relationelem(); r_elem.a_class = semi[loc + 1].ToString(); r_elem.b_class = semi[loc + 2].ToString(); r_elem.isInheritance = true; repo_.classrelations.Add(r_elem); } } //**************************** check for aggregation**************// if (semi.Contains("aggregation") != -1) { int loc = semi.Contains("aggregation"); if (loc != -1) { Elem e = new Elem(); e.type = semi[loc + 2]; e.name = semi[loc + 1]; repo_.stack.push(e); int i = rep.locations.Count; Elem temp = rep.locations[i - 1]; if (semi[1] != temp.name) { relationelem r_elem = new relationelem(); r_elem.a_class = temp.name; r_elem.b_class = semi[1].ToString(); r_elem.isAggregation = true; repo_.classrelations.Add(r_elem); } } } if (AAction.displaySemi) { //Console.Write("\n line# {0,-5}", repo_.semi.lineCount - 1); //Console.Write("entering "); //string indent = new string(' ', 2 * repo_.stack.count); //Console.Write("{0}", indent); //this.display(semi); // defined in abstract action } if (AAction.displayStack) { repo_.stack.display(); } }
public override void doAction(CSsemi.CSemiExp semi) { RelElem Relem = new RelElem(); Relem.type = semi[0]; // expects relationship Relem.name = semi[1]; //expects name Relem.withName = semi[2]; // expects withname Relem.beginRel = repo_.semi.lineCount - 1 - repo_.prevLineCount; if (semi[0].Equals("Aggregation")) { Relem.endRel = repo_.semi.lineCount - 1 - repo_.prevLineCount; } else if (semi[0].Equals("Composition")) { Relem.endRel = repo_.semi.lineCount - 1 - repo_.prevLineCount; } else if (semi[0].Equals("Using")) { Relem.endRel = repo_.semi.lineCount - 1 - repo_.prevLineCount; } else if (semi[0].Equals("UsingTemp")) { Relem.endRel = repo_.semi.lineCount - 1 - repo_.prevLineCount; } else if (semi[0].Equals("UsingStr")) { Relem.endRel = repo_.semi.lineCount - 1 - repo_.prevLineCount; } else if (semi[0].Equals("Inheritance")) { Relem.endRel = repo_.semi.lineCount - 1 - repo_.prevLineCount; } else { Relem.endRel = 0; repo_.stack2.push(Relem); } if (Relem.type == "control" || Relem.name == "anonymous" || Relem.withName == "anonymous2") { return; } repo_.inheritance.Add(Relem); if (AAction.displaySemi) { Console.Write("\n line# {0,-5}", repo_.semi.lineCount - 1); Console.Write("entering "); string indent = new string(' ', 2 * repo_.stack.count); Console.Write("{0}", indent); this.display(semi); // defined in abstract action } if (AAction.displayStack) { repo_.stack.display(); } }
//----< Test Stub >-------------------------------------------------- #if (TEST_PARSER) static void Main(string[] args) { Console.Write("\n Demonstrating Parser"); Console.Write("\n ======================\n"); ShowCommandLine(args); /* If the package is run as stand alone application * then add the default values for the member variables */ try { 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(); semi.close(); Console.ReadLine(); } } catch { Console.WriteLine("Error in parsing"); } }
public override void doAction(CSsemi.CSemiExp semi) { TypeElement elem = new TypeElement(); elem.Type = semi[0]; // expects type elem.TypeName = semi[1]; // expects name repo_.userDefinedTypes.Add(elem); }
public virtual Parser build2(Repository repo, CSsemi.CSemiExp semi2) { //repo.semi.lineCount = 0; repo.semi = semi2; repo.prevLineCount = semi2.lineCount; //Console.WriteLine("semi2 line count is {0}", semi2.lineCount); Parser parser = new Parser(); // decide what to show AAction.displaySemi = false; AAction.displayStack = false; // this is default so redundant // action used for namespaces, classes, and functions PushStack2 push2 = new PushStack2(repo); //detect inheritance DetectInheritance detectI = new DetectInheritance(); detectI.add(push2); parser.add(detectI); //Console.WriteLine("{0}",repo.locations); //detect aggregation DetectAggregation detectAGR = new DetectAggregation(); detectAGR.add(push2); parser.add(detectAGR); // detect using DetectUsing detectUSG = new DetectUsing(); detectUSG.add(push2); parser.add(detectUSG); //detect composition DetectComposition detectComp = new DetectComposition(); detectComp.add(push2); parser.add(detectComp); //detect anonymous scope /* DetectAnonymousScope2 anon = new DetectAnonymousScope2(); * anon.add(push2); * parser.add(anon); */ // handle leaving scopes /* DetectLeavingScope leave = new DetectLeavingScope(); * PopStack2 pop2 = new PopStack2(repo); * leave.add(pop2); * parser.add(leave); */ // parser configured return(parser); }
/// <summary> /// Creates data for the package dependency analysis /// </summary> /// <param name="relationName">1 of the 4 relations</param> /// <param name="semi">current semi</param> /// <param name="parentServerIndex">the index of the analyzed data where the server information is stored</param> private void createPackageAnalysisList(string relationName, CSsemi.CSemiExp semi, int parentServerIndex) { try { PackageDependencyElem packageelem = new PackageDependencyElem(); int parentServerNameIndex = 0; int childServerNameIndex = 0; int childTypeBeginLine = repo_.semi.lineCount - 1; int childIndexInRepo = 0; if (relationName.Equals("Inheritance")) { childIndexInRepo = findChildTypeIndexInheritance(semi[0], childTypeBeginLine); } else { childIndexInRepo = findChildTypeIndex(semi[0]); } parentServerNameIndex = findServerIndex(parentServerIndex); childServerNameIndex = findServerIndex(childIndexInRepo); string parentPackage = repo_.analyzedata[parentServerNameIndex].packageName; string childPackage = repo_.analyzedata[childServerNameIndex].packageName; packageelem.parentPackage = parentPackage; packageelem.parentServerName = repo_.analyzedata[parentServerNameIndex].serverName; if (!parentPackage.Equals(childPackage)) { packageelem.typeName1 = semi[1]; packageelem.typeName2 = semi[0]; packageelem.relationship = relationName; packageelem.childPackageName = childPackage; packageelem.childServerName = repo_.analyzedata[childServerNameIndex].serverName; if (repo_.packagedata.Count > 0) { for (int i = 0; i < repo_.packagedata.Count;) { PackageDependencyElem curr = repo_.packagedata[i]; if (packageelem.isEqual(curr)) { break; } else { repo_.packagedata.Add(packageelem); break; } } } else { repo_.packagedata.Add(packageelem); } } //} } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void TryActionOnAggregation(CSsemi.CSemiExp semi) { if (isInterestedType(semi[1])) { string relationship = semi[0]; TypeElement parent = allLocallyDeclaredTypes.GetTypeElement(getContainingClass()); TypeElement child = interestedTypes.GetTypeElement(semi[1]); repo_.relationshipTable.add(parent, child);; } }
public override void display(CSsemi.CSemiExp semi) { for (int i = 0; i < semi.count; ++i) { if (semi[i] != "\n" && !semi.isComment(semi[i])) { Console.Write("{0} ", semi[i]); } } }
public virtual void display(CSsemi.CSemiExp semi) { if (displaySemi) { for (int i = 0; i < semi.count; ++i) { Console.Write("{0} ", semi[i]); } } }
public override bool test(CSsemi.CSemiExp semi) { int index = semi.Contains("}"); if (index != -1) { doActions(semi); return(true); } return(false); }
//----<set of actions if there is inheritance between two types>---------------- public void doActionInheritance(CSsemi.CSemiExp semi, string file, ElemRelation elem) { if (semi[0].Equals("Inheritance")) { elem.fromClass = semi[1]; elem.toClass = semi[2]; elem.relationType = semi[0]; elem.fileName = file; RelationshipRepository.relationship_.Add(elem); } }
public override void doAction(CSsemi.CSemiExp semi) { Elem elem = new Elem(); elem.type = semi[0]; // expects type elem.name = semi[1]; // expects name elem.begin = repo_.semi.lineCount - 1; elem.end = 0; repo_.stack.push(elem); }
private void inheritance(CSsemi.CSemiExp semi, string filename) { ElemRelation elem = new ElemRelation(); elem.definedType = semi[0]; elem.relationType = semi[1]; elem.fromName = semi[2]; elem.toName = semi[3]; elem.filename = filename; RepositoryForRelation.storageForRelationship_.Add(elem); }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectComment"); if (semi.Contains("//") != -1 || semi.Contains("/*") != -1) { doActions(semi); return(true); } return(false); }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectLeavingScope"); int index = semi.Contains("}"); if (index != -1) { doActions(semi); return(true); } return(false); }
public override void display(CSsemi.CSemiExp semi) { Console.Write("\n line# {0}", repo_.semi.lineCount - 1); Console.Write("\n "); for (int i = 0; i < semi.count; ++i) { if (semi[i] != "\n" && !semi.isComment(semi[i])) { Console.Write("{0} ", semi[i]); } } }
protected CSsemi.CSemiExp GetSemiExpressionFromFile(object file) { 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(null); } return(semi); }
public override void doAction(CSsemi.CSemiExp semi) { if (semi[0].StartsWith("//") || semi[0].StartsWith("/*")) { ++repo_.scopeCount; Elem commentElm = new Elem(); commentElm.type = "Comment"; commentElm.name = semi[0]; repo_.stack.push(commentElm); if (AAction.displayStack) { repo_.stack.display(); } if (AAction.displaySemi) { Console.Write("\n line# {0,-5}", repo_.semi.lineCount - 1); Console.Write("entering "); string indent = new string(' ', 2 * repo_.stack.count); Console.Write("{0}", indent); this.display(semi); // defined in abstract action } return; } Display.displayActions(actionDelegate, "action PushStack"); ++repo_.scopeCount; Elem elem = new Elem(); elem.type = semi[0]; // expects type elem.name = semi[1]; // expects name elem.beginLine = repo_.semi.lineCount - 1; elem.endLine = 0; elem.beginScopeCount = repo_.scopeCount; elem.endScopeCount = 0; repo_.stack.push(elem); if (AAction.displayStack) { repo_.stack.display(); } if (AAction.displaySemi) { Console.Write("\n line# {0,-5}", repo_.semi.lineCount - 1); Console.Write("entering "); string indent = new string(' ', 2 * repo_.stack.count); Console.Write("{0}", indent); this.display(semi); // defined in abstract action } if (elem.type == "control" || elem.name == "anonymous") { return; } repo_.locations.Add(elem); }
static public void doAnalysis(string[] files) { int skipCount = 0; CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); Repository rep = Repository.getInstance(); foreach (string file in files) { if (Display.showFiles) { Display.displayString(""); } Display.displayFiles(act, "Processing file: " + file); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } List <Elem> table = rep.locations; if (table.Count == 0) { ++skipCount; continue; } semi.close(); rep.LocationsTable[file] = table; rep.locations = new List <Elem>(); } displaySkipped(skipCount); displayAnalysis(rep); analysisSummary(rep); }
public int indexOfType(CSsemi.CSemiExp semi) { int indexCL = semi.Contains("class"); int indexIF = semi.Contains("interface"); int indexST = semi.Contains("struct"); int indexEN = semi.Contains("enum"); int index = Math.Max(indexCL, indexIF); index = Math.Max(index, indexST); index = Math.Max(index, indexEN); return(index); }
private int GetFirstNonNewLineIndex(CSsemi.CSemiExp semi) { int i = 0; for (; i < semi.count; i++) { if (semi[i] != "\n") { break; } } return(i); }
//----< Test Stub for Parser >-------------------------------------------------- #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) { string filename = Convert.ToString(file); 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, filename); } 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) { if (e.type == "function") { Console.Write("\n {0,10}, {1,25}, {2,5}, {3,5}, {4,5}", e.type, e.name, e.begin, e.end, e.functionComplexity); } } Console.WriteLine(); Console.Write("\n\n That's all folks!\n\n"); semi.close(); } }
public override void doAction(CSsemi.CSemiExp semi, string filename) { if (semi[1].Equals("Inheritance")) //Action for Inheritance { inheritance(semi, filename); return; } if (semi[0].Contains("Aggregation")) { aggregation(semi, filename); return; } if (semi[0].Contains("Composition")) { composition(semi, filename); return; } if (semi[0].Contains("Using")) { usingRelation(semi, filename); return; } if (semi[0].Contains("namespace")) { Elem ele = new Elem(); ele.type = semi[0]; ele.name = semi[1]; ele.filename = filename; repo_.locations.Add(ele); } if (semi[0].Contains("class")) { Elem ele = new Elem(); ele.type = semi[0]; ele.name = semi[1]; ele.filename = filename; repo_.locations.Add(ele); } if (AAction.displaySemi) { Console.Write("\n line# {0,-5}", repo_.semi.lineCount - 1); Console.Write("entering "); string indent = new string(' ', 2 * repo_.stack.count); Console.Write("{0}", indent); this.display(semi); // defined in abstract action } if (AAction.displayStack) { repo_.stack.display(); } }
protected void ParseSemi(CSsemi.CSemiExp semi, Parser parser) { try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } }
// Parses the files to extract relationships among userdefined types protected override bool ParseFile(String file) { CSsemi.CSemiExp semi = GetSemiExpressionFromFile(file); if (semi == null) { return(false); } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.buildParserForRelationships(interestedTypes, allTypes); ParseSemi(semi, parser); semi.close(); return(true); }
//----< remove c# keywords from semi expression >------------------------------ static public CSsemi.CSemiExp RemoveKeywords(CSsemi.CSemiExp s) { CSsemi.CSemiExp newSemi = new CSsemi.CSemiExp(); for (int i = 0; i < s.count; i++) { if (s[i] != "static") { newSemi.Add(s[i]); } } return newSemi; }
/// <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"); } }
public void parse(CSsemi.CSemiExp semi) { foreach (IRule rule in Rules) { if (rule.test(semi)) { break; } } if (rule.test(semi) != 0) { Add(rule); } }
private void aggregationTest(CSsemi.CSemiExp semi, int index, string filename, string filenameto, string namespacename) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); if ((semi[index + 2].Equals("."))) { local.Add("Aggregation").Add(semi[index + 3]).Add(semi[index - 2]).Add(filenameto).Add(namespacename); doActions(local, filename); } else { local.Add("Aggregation").Add(semi[index + 1]).Add(semi[index - 2]).Add(filenameto).Add(namespacename); doActions(local, filename); } }
//This method applies all the rule present in the parser object to each of the semi expression public void parse(CSsemi.CSemiExp semi) { // Note: rule returns true to tell parser to stop // processing the current semiExp foreach (IRule rule in Rules) { //semi.display(); if (rule.test(semi)) { break; } } }
static public void doAnalysis(string[] files,bool relationship) { BuildCodeAnalyzer builder; BuildCodeAnalyzer_relation builder_relation; Parser parser; Parser parser_; for(int i=0;i<2;i++) { foreach (object file in files) { CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); CSsemi.CSemiExp semi_relation = new CSsemi.CSemiExp(); semi.displayNewLines = false; if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } if (!semi_relation.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } if (i == 0) { builder = new BuildCodeAnalyzer(semi); parser = builder.build(); Repository rep1 = Repository.getInstance(); rep1.setfilename(Path.GetFileName(file.ToString())); try { while (semi.getSemi()) parser.parse(semi); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } } else { builder_relation = new BuildCodeAnalyzer_relation(semi_relation); parser_ = builder_relation.build_relation(); Repository rep1 = Repository.getInstance(); rep1.setfilename(Path.GetFileName(file.ToString())); try { while (semi_relation.getSemi()) parser_.parse(semi_relation); } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } } semi.close(); } if (!relationship) return; } }
static void doAnalysis(string[] files) { Console.Write("\n Demonstrating Parser"); Console.Write("\n ======================\n"); 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; } 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} , {4,5}", e.type, e.name, e.begin, e.end, e.end - e.begin + 1); } Console.WriteLine(); Console.Write("\n\n That's all folks!\n\n"); semi.close(); } }
//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(); } }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectNamespace"); int index = semi.Contains("namespace"); if (index != -1) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // create local semiExp with tokens for type and name local.displayNewLines = false; local.Add(semi[index]).Add(semi[index + 1]); doActions(local); return true; } return false; }
public override bool test(CSsemi.CSemiExp semi) { if (semi[semi.count - 1] != "{") return false; // strip off leading #if(TEST_XYZ) if it's in this semi if (semi.FindFirst("#") != -1) { int loc = semi.FindFirst(")"); for (int i = 0; i <= loc; ++i) semi.remove(0); } // now find function int index = semi.FindFirst("("); if (index > 0 && !isSpecialToken(semi[index - 1])) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); local.Add("function").Add(semi[index - 1]); doActions(local); return true; } return false; }
public override bool test(CSsemi.CSemiExp semi, string filename) { if (semi[semi.count - 1] != "{") return false; int index = semi.FindFirst("("); List<Elem> table = RepositoryForOutput.storageForOutput_; CSsemi.CSemiExp local = new CSsemi.CSemiExp(); try { if (index > 0 && !isSpecialToken(semi[index - 1])) { for (int i = index - 1; i < semi.count; i++) { foreach (Elem e in table) { if ((e.name.Equals(semi[i])) && !(e.type.Equals("function")) && !(e.type.Equals("namespace"))) { local.Add("Using").Add(semi[i]).Add(e.filename).Add(e.namespacename); doActions(local, filename); return false; } } } } } catch { } return false; }
public override bool test(CSsemi.CSemiExp semi, string filename) { if (semi[semi.count - 1] != "{") return false; int index = semi.FindFirst("("); if (index > 0 && !isSpecialToken(semi[index - 1])) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); local.Add("function").Add(semi[index - 1]); doActions(local, filename); return true; } return false; }
public void findDefinedTypes(string file) { CodeAnalysis.Parser p = new CodeAnalysis.Parser(); enterScopeRule esr = new enterScopeRule(); displayEnterScope des = new displayEnterScope(); esr.add(des); p.add(esr); CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); if (!semi.open(file)) { Console.Write("\n\n can't open file {0} for analysis\n", file); } while (semi.getSemi()) p.parse(semi); }
//----< 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 (string file in files) { 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 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.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}", "--------", "----", "-----", "-----", "-----", "-----", "----", "-----" ); foreach (Elem e in table) { if (e.type == "class" || e.type == "struct") 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 ); } Console.Write("\n"); semi.close(); } Console.Write("\n\n"); }
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); }
public void RelationshipAnalyzer(Elem e, Object file, List<Elem> TABLE) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); local.open(file as string); while (local.lineCount < e.begin) { local.getSemi(); } while (local.lineCount < e.end) { InheritanceAnalyze(local, TABLE); AggregationAnalyze(local, TABLE); CompositionAnalyze(local, TABLE); UsingAnalyze(local, TABLE, e); local.getSemi(); } }
public override void doAction(CSsemi.CSemiExp semi, string filename) { Elem elem; try { elem = repo_.stack.pop(); for (int i = 0; i < repo_.locations.Count; ++i) { Elem temp = repo_.locations[i]; if (elem.type == temp.type) { if (elem.name == temp.name) { if ((repo_.locations[i]).end == 0) { (repo_.locations[i]).end = repo_.semi.lineCount; elem.end = repo_.semi.lineCount; break; } } } } } catch { Console.Write("popped empty stack on semiExp: "); semi.display(); return; } CSsemi.CSemiExp local = new CSsemi.CSemiExp(); local.Add(elem.type).Add(elem.name); if (local[0] == "control") return; if (AAction.displaySemi) { Console.Write("\n line# {0,-5}", repo_.semi.lineCount); Console.Write("leaving "); string indent = new string(' ', 2 * (repo_.stack.count + 1)); Console.Write("{0}", indent); this.display(local); // defined in abstract action } }
public override bool test(CSsemi.CSemiExp semi, string filename) { int indexCL = semi.Contains("class"); int indexIF = semi.Contains("interface"); int indexST = semi.Contains("struct"); int indexEN = semi.Contains("enum"); int index = Math.Max(indexCL, indexIF); index = Math.Max(index, indexST); index = Math.Max(index, indexEN); 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]); doActions(local, filename); return true; } return false; }
public override bool test(CSsemi.CSemiExp semi, string filename) { string[] SpecialToken = { "try", "for", "foreach", "while", "switch", "if", "else", "catch", "using", "unsafe", "finally", "break" }; int index = -1; foreach (string stoken in SpecialToken) { index = semi.Contains(stoken); if (index != -1) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // create local semiExp with tokens for type and name local.displayNewLines = false; local.Add("complexity"); doActions(local, filename); return false; } } return false; }
public override bool test(CSsemi.CSemiExp semi, string filename) { int index = semi.Contains("delegate"); if (index != -1) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // create local semiExp with tokens for type and name local.displayNewLines = false; local.Add(semi[index]).Add(semi[index + 2]); doActions(local, filename); return true; } return false; }
public override bool test(CSsemi.CSemiExp semi) { int indexEN = semi.Contains("enum"); if (indexEN != -1) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); local.displayNewLines = false; local.Add(semi[indexEN]).Add(semi[indexEN + 1]); doActions(local); return true; } return false; }
private void inhertanceTest(CSsemi.CSemiExp semi, int index, string filename) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); CSsemi.CSemiExp local1 = new CSsemi.CSemiExp(); local.displayNewLines = false; local1.displayNewLines = false; if ((semi[index + 2].Equals(":"))) { foreach (Elem check in table) { if (check.name.Equals(semi[index + 3])) { local.Add(semi[index]).Add("Inheritance").Add(semi[index + 1]).Add(semi[index + 3]).Add(check.filename).Add(check.namespacename); doActions(local, filename); break; } } } if ((semi[index + 2].Equals(":")) && (semi[index + 4].Equals(","))) { foreach (Elem check in table) { if (check.name.Equals(semi[index + 5])) { local1.Add(semi[index]).Add("Inheritance").Add(semi[index + 1]).Add(semi[index + 5]).Add(check.filename).Add(check.namespacename); doActions(local1, filename); break; } } } }
public void relationshipanalysis(Elem e, object file, List<Elem> fileSetInfo) { CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.open(file as string); do { semi.getSemi(); } while (semi.lineCount < (e.begin-1)); // ignore semi before type define while (semi.lineCount <= e.end) { // detect four kinds of relationship inheritance(semi, e); aggregation(semi, e, fileSetInfo); composition(semi, e, fileSetInfo); usingRelationship(semi, e, fileSetInfo); semi.getSemi(); } return; }
public override bool test(CSsemi.CSemiExp semi, string filename) { List<Elem> table = RepositoryForOutput.storageForOutput_; CSsemi.CSemiExp local = new CSsemi.CSemiExp(); try { for (int i = 0; i < semi.count; i++) { foreach (Elem e in table) { if ((e.name.Equals(semi[i])) && ((e.type.Equals("struct")) || (e.type.Equals("enum"))) && !(e.type.Equals("function")) && (semi[i + 2].Equals(";"))) { local.Add("Composition").Add(semi[i]).Add(e.filename).Add(e.namespacename); doActions(local, filename); return true; } } } } catch { } return false; }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectClass"); int indexCL = semi.Contains("class"); int indexIF = semi.Contains("interface"); int indexST = semi.Contains("struct"); int index = Math.Max(indexCL, indexIF); index = Math.Max(index, indexST); 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]); doActions(local); return true; } return false; }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectPublicDeclar"); int index = semi.Contains(";"); if (index != -1) { index = semi.Contains("public"); if (index == -1) return true; CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // create local semiExp with tokens for type and name local.displayNewLines = false; local.Add("public "+semi[index+1]).Add(semi[index+2]); index = semi.Contains("="); if (index != -1) { doActions(local); return true; } index = semi.Contains("("); if(index == -1) { doActions(local); return true; } } return false; }
public override bool test(CSsemi.CSemiExp semi) { int index = semi.Contains("{"); if (index != -1) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // create local semiExp with tokens for type and name local.displayNewLines = false; local.Add("control").Add("anonymous"); doActions(local); return true; } return false; }
public int complexityAnalysis(Elem e, object file, List<Elem> fileSetInfo) { int count = 0; CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.open(file as string); do { semi.getSemi(); } while (semi.lineCount < e.begin); // ignore all the semi before function begin while (semi.lineCount <= e.end) { if (semi.Contains("if") != -1) count++; if (semi.Contains("else") != -1) count++; if (semi.Contains("for") != -1) count++; if (semi.Contains("foreach") != -1) count++; if (semi.Contains("while") != -1 && semi[semi.count - 1] != ";") count++; if (semi.Contains("do") != -1) count++; if (semi.Contains("case") != -1) count++; if (semi.Contains("try") != -1) count++; if (semi.Contains("catch") != -1) count++; if (specialCB(semi)) // special curly brace count++; semi.getSemi(); } return count; }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectFunction"); if (semi[semi.count - 1] != "{") return false; int index = semi.FindFirst("("); if (index > 0 && !isSpecialToken(semi[index - 1])) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); local.Add("function").Add(semi[index - 1]); doActions(local); return true; } return false; }