public override bool test(ITokenCollection semi) { Display.displayRules(actionDelegate, "rule DetectUsing"); int index; semi.find("using", out index); if (index != -1 && semi.size() > index + 1) { ITokenCollection local = Factory.create(); // create local semiExp with tokens for type and name if (semi[index + 2].Equals("=") && semi[semi.size() - 1].Equals(";")) { local.add("alias"); local.add(semi[index + 1]); local.add(semi[index + 3]); doActions(local); return(true); } if (!semi[index + 1].Equals("System")) { local.add(semi[index]).add(semi[index + 1]); doActions(local); return(true); } } return(false); }
static void Main(string[] args) { Console.Write("\n testing Semi"); Console.Write("\n =============="); // Access Semi through interface and object factory. // That isolates client from any changes that may occur to Semi // as long as ITokenCollection doesn't change. ITokenCollection semi = Factory.create(); string source = "../../semi.cs"; if (!semi.open(source)) { Console.Write("\n Can't { 0}\n", source); return; } while (!semi.isDone()) { semi.get(); semi.show(); } Console.Write("\n"); Console.Write("\n demonstrating semi operations"); Console.Write("\n -------------------------------"); ITokenCollection test = Factory.create(); checkSemiTest(test); Console.Write("\n\n"); }
public int indexOfType(ITokenCollection semi) { int indexCL; semi.find("class", out indexCL); int indexIF; semi.find("interface", out indexIF); int indexST; semi.find("struct", out indexST); int indexEN; semi.find("enum", out indexEN); int indexDE; semi.find("delegate", out indexDE); var index = Math.Max(indexCL, indexIF); index = Math.Max(index, indexST); index = Math.Max(index, indexEN); index = Math.Max(index, indexDE); return(index); }
public override bool test(ITokenCollection semi) { Display.displayRules(actionDelegate, "rule DetectClass"); int indexCL; semi.find("class", out indexCL); int indexIF; semi.find("interface", out indexIF); int indexST; semi.find("struct", out indexST); int indexEN; semi.find("enum", out indexEN); int index = Math.Max(indexCL, indexIF);// to find which one i got. no found -1 index = Math.Max(index, indexST); index = Math.Max(index, indexEN); if (index != -1 && semi.size() > index + 1) { ITokenCollection local = Factory.create(); // local semiExp with tokens for type and name local.add(semi[index]).add(semi[index + 1]); // local.add(semi[index + 1]).add(semi[index]); doActions(local); return(true); } return(false); }
public void doActions(ITokenCollection semi) { foreach (var action in actions) { action.doAction(semi); } }
public void RemoveRange(ITokenCollection tokens) { if (tokens==null) throw new ArgumentNullException("tokens"); foreach(Object token in tokens) this.List.Remove(token); }
ITokenCollection compactGeneric(ITokenCollection semi) { ITokenCollection aClone = new Semi(); int start, stop; semi.find("<", out start); if (start == -1) { return(semi); } semi.find(">", out stop); if (stop == -1) { return(semi); } for (int i = 0; i <= start - 2; ++i) { aClone.add(semi[i]); } string newTok = ""; for (int i = start - 1; i < stop + 1; ++i) { newTok += semi[i]; } //aClone.add(newTok); // this comment causes compaction to remove generic params aClone.add(semi[start - 1]); for (int i = stop + 1; i < semi.size(); ++i) { aClone.add(semi[i]); } return(aClone); }
public override bool test(ITokenCollection semi) { Display.displayRules(actionDelegate, "rule DetectPublicDeclar"); int index; semi.find(";", out index); if (index != -1) { semi.find("public", out index); if (index == -1) { return(true); } ITokenCollection local = Factory.create(); // create local semiExp with tokens for type and name //local.displayNewLines = false; local.add("public " + semi[index + 1]).add(semi[index + 2]); semi.find("=", out index); if (index != -1) { doActions(local); return(true); } semi.find("(", out index); if (index == -1) { doActions(local); return(true); } } return(false); }
//---------------<Exetract type information from collection of files>------------ public void AnalyzeFiles() { foreach (string filepath in files_) { ITokenCollection semi = Factory.create(); if (!semi.open(filepath)) { Console.WriteLine("Cannot open file {0}", filepath); continue; } string filename = Filename(filepath); BuildTypeAnalyzer typeAnalysis = new BuildTypeAnalyzer(semi, filename); Parser typeParser = typeAnalysis.build(); try { while (semi.get().Count > 0) { typeParser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } } Repository repo = Repository.getInstance(); repo.MapAlias(); }
static void Main(string[] args) { ShowCommandLine(args); Executive test = new Executive(); test.requirementOne(); test.requirementTwo(); test.requirementThree(); test.requirementFour(); List <string> files = ProcessCommandline(args); 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(); List <Elem> table = rep.locations; semi.close(); } test.setAllParameters(files); foreach (string file in files) { Console.Write("\nFilename : {0}\n", System.IO.Path.GetFileName(file)); DAnalysis depAnls = new DAnalysis(); ITokenCollection semi = Factory.create(); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", args[0]); return; } try{ while (semi.get().Count > 0) { depAnls.parse(semi, file); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); Graph.addGraph(); } test.setAllParams(); test.requirementSix(); test.requirementSeven(); }
public override bool test(ITokenCollection semi) { Repository repo = Repository.getInstance(); ITokenCollection local = semi.clone(); if (local[0] == "using") { return(false); } Display.displayRules(actionDelegate, "rule DetectDeclar"); int index; local.find(";", out index); if (index != -1) { local = compactGeneric(local); int pos = 0; while (pos < local.size()) { if (repo.qualTable.contains(local[pos])) { local.remove(pos); } else { ++pos; } } local.find("=", out index); if (index != -1) { while (index < local.size() - 1) { local.remove(index); } } int indexPar; local.find("(", out indexPar); if (indexPar > -1) { return(false); } if (local.size() == 3) { doActions(local); return(false); } if (local.size() == 5 && local[1] == ".") { doActions(local); return(false); } } return(false); }
public IEnumerable <TokenGroup> GroupTokens(ITokenCollection tokens) { foreach (var groupTokens in SplitBySpaceTokens(tokens)) { var tokenGroup = new TokenGroup(groupTokens); yield return(tokenGroup); } }
public static void DemoSemiTst(ITokenCollection test) { Console.Write("\n demonstrate semi tests"); if (test.hasTerminator()) Console.Write("\n semi has terminator"); else Console.Write("\n semi does not have terminator"); }
public IEnumerable <IToken> Assemble(ITokenCollection tokens) { var digitTokens = tokens.OfType <DigitToken>().ToArray(); var numberStr = digitTokens.Aggregate("", (accumulator, token) => accumulator + token.Value); var number = double.Parse(numberStr); yield return(new NumberToken(number)); }
public override void doAction(ITokenCollection semi) { if (repo_.semi.isDone()) { repo_.addNode(currentNode_); repo_.graph_.startNode = currentNode_; } }
//----< Test Stub >-------------------------------------------------- #if (TEST_PARSER) static void Main(string[] args) { List <List <Elem> > allTables = new List <List <Elem> >(); 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)); 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, file); 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; allTables.Add(table); Console.Write("\n"); semi.close(); } Display.showMetricsNamespace(allTables); Display.showMetricsClass(allTables); Display.showMetricsFunction(allTables); Display.showMetricsAlias(allTables); Display.showMetricsEnum(allTables); Display.showMetricsStruct(allTables); Display.showMetricsDelegate(allTables); Display.showMetricsUsing(allTables); Display.showMetricsInterface(allTables); Console.Write("\n\n"); }
void TypeAnalys(List <string> files, string displaytokenfile, bool check) { if (check) { Console.Write("\n Type Analysis"); Console.Write("\n ---------------"); Console.Write( "\n {0,10} {1,25} {2,25}", "category", "name", "file" ); Console.Write( "\n {0,10} {1,25} {2,25}", "--------", "----", "----" ); } ITokenCollection semi = Factory.create(); BuildTypeAnalyzer builder = new BuildTypeAnalyzer(semi); Parser parser = builder.build(); Repository repo = Repository.getInstance(); foreach (string file in files) { if (file.Contains("TemporaryGeneratedFile")) { continue; } if (!semi.open(file as string)) { //Console.Write("\n Can't open {0}\n\n", args[0]); continue; } repo.currentFile = file; repo.locations.Clear(); 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; if (check) { Display.showMetricsTable(table); Console.Write("\n"); TypeAnalysWrittenFile(displaytokenfile, table); } semi.close(); } }
public virtual void LoadTokenCollection(ITokenCollection <IToken> collection) { if (collection != null) { TokenCacheUpdateTimes[collection.GetCollectionLabel()] = GetDatabase().GetItem(collection.GetBackingItemId()).Statistics.Updated; TokenCollections[collection.GetCollectionLabel()] = collection; } }
public TokenCollectionSplit( IToken delimiter, ITokenCollection left, ITokenCollection right) { Delimiter = delimiter; Left = left; Right = right; }
public override void doAction(ITokenCollection semi) { String file = repo_.filename; String namespace_ = repo_.namespaceStack.Peek(); String type = semi[0]; TypeTableEle e = new TypeTableEle(type, namespace_, file); repo_.table.add(semi[1], semi[0], namespace_, file); }
public override bool test(ITokenCollection semi) { if (semi.isDone()) { doActions(semi); return(true); } return(false); }
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"); }
public override void doAction(ITokenCollection semi) { if (repo_.semi.isDone()) { Console.WriteLine("NODE {0} has been added", currentNode_.name); repo_.addNode(currentNode_); repo_.graph_.startNode = currentNode_; } }
//--------<GetTable implement opreation to get a typetable from semi and retrun a whole typetable>----- public TypeTable GetTable(string[] args) { TestType tp = new TestType(); TypeTable tt = new TypeTable(); //FileFinder filef = new FileFinder(); //args = filef.get_cs(); foreach (var item in args) { //Console.WriteLine(item); } foreach (string file in args) { ITokenCollection semiexp = Factory.create(); if (!semiexp.open(file as string)) { Console.Write("\n Can't open {0}\n\n", args[0]); break; } BuildCodeAnalyzers builder = new BuildCodeAnalyzers(semiexp); Parser parser = builder.build(); try { while (semiexp.get().Count > 0) { parser.parse(semiexp); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); List <Elem> table = rep.locations; string name = ""; foreach (Elem e in table) { if (e.type == "namespace") { name = e.name; } else { if (e.type == "Alias" || e.type == "function") { continue; } tt.add(e.name, System.IO.Path.GetFileName(file), name, e.type); //Console.WriteLine("Pass this route"); } } semiexp.close(); } Console.WriteLine(tt.table.Count); return(tt); }
public void SimulateStep() { // first step, iterate over arc and gather tokens in transitions foreach (IArc arc in this.net.Arcs) { if (!arc.IsInputArc) { continue; } ITokenCollection tokens = (ITokenCollection)this.transitionBuffers[arc.Transition]; // get annotated tokens ITokenCollection annotatedTokens = arc.Annotation.Eval(arc.Place.Marking); //add annontated tokens tokens.AddRange(annotatedTokens); } // second step, see which transition was enabled foreach (ITransition tr in this.Net.Transitions) { // get buffered tokens ITokenCollection tokens = (ITokenCollection)this.transitionBuffers[tr]; // check if enabled, store value this.transitionEnabled[tr] = tr.Condition.IsEnabled(tokens); } // third step, iterate over the arcs foreach (IArc arc in this.Net.Arcs) { if (!(bool)this.transitionEnabled[arc.Transition]) { continue; } if (arc.IsInputArc) { // get annotated tokens ITokenCollection annotatedTokens = arc.Annotation.Eval(arc.Place.Marking); // remove annotated comments from source place arc.Place.Marking.RemoveRange(annotatedTokens); } else { ITokenCollection tokens = (ITokenCollection)this.transitionBuffers[arc.Transition]; // get annotated tokens ITokenCollection annotatedTokens = arc.Annotation.Eval(tokens); // adding annotated comments to target place arc.Place.Marking.AddRange(annotatedTokens); } } // step four, clear buffers foreach (ITransition tr in this.Net.Transitions) { ((ITokenCollection)this.transitionBuffers[tr]).Clear(); this.transitionEnabled[tr] = false; } }
public void Requirement4_5(string[] args) { Console.Write("\n\t \tOutput of Requirement4\n"); Console.Write("-----------------------------------------------------------------------------\n"); Console.Write("This Project3 implements packages that evaluate all the dependencies between files in a specified file set"); ShowCommandLine(args); List <string> files = ProcessCommandline(args); Executive test = new Executive(); test.Execute_Parser(files); test.Execute_TypeAnalyzer(); DepAnalysis.DepAnalysis dep = new DepAnalysis.DepAnalysis(); StrongComp.filesGraphs = files; StrongComp.filenumber = files.Count(); StrongComp.setGraph(); DepAnalysis.DepAnalysis.filesDepAnalysis = files; StrongComp.filesGraph = files; DepAnalysis.DepAnalysis.setDictionary(); StrongComp.setGraphDictionary(); Console.Write("\nDemonstrating Output Of Dependency Analysis"); Console.Write("\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", files[0]); return; } try { while (semi.get().Count > 0) { dep.HoldUsingValue(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", files[0]); return; } try { while (semi.get().Count > 0) { dep.analyze(semi, file); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } StrongComp.addGraph(); semi.close(); } Console.Write("\n\n"); }
//----< Test Stub >-------------------------------------------------- #if (TEST_PARSER) static void Main(string[] args) { TypeTable tb = new TypeTable(); 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)); 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 ----------------------------"); string name = ""; for (int i = file.Length - 1; file[i] != '/' && file[i] != '\\'; --i) { name = file[i] + name; } Console.WriteLine("FILE: {0}", name); BuildTypeAnalyzer builder = new BuildTypeAnalyzer(semi, name); 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"); tb.print(); Console.ReadLine(); }
//void dummy(Elem elem) { } public virtual void display(ITokenCollection semi) { if (displaySemi) { for (var i = 0; i < semi.size(); ++i) { Console.Write("{0} ", semi[i]); } } }
public override void doAction(ITokenCollection semi) { String file1 = semi[0]; // file1 dependes on file2 String file2 = semi[1]; if (!repo_.dependencyTable[file1].Contains(file2)) { repo_.dependencyTable[semi[0]].Add(semi[1]); } }
public TokenGroup(ITokenCollection tokens) { if (tokens == null) { throw new ArgumentNullException(nameof(tokens)); } Tokens = tokens; TokenTypes = tokens.Select(t => t.GetType()).Distinct().ToArray(); }
public override bool test(ITokenCollection semi) { Display.displayRules(actionDelegate, "rule DetectInheritance"); int indexCL; semi.find("class", out indexCL); int indexIF; semi.find("interface", out indexIF); int indexC; semi.find(":", out indexC); // int indexST; // semi.find(".", out indexST); int indexCM; semi.find("=", out indexCM); //Console.WriteLine("For \n class {0}\ninterface {1}\n: {2}\n= {3}",indexCL,indexIF,indexC,indexCM); int index = Math.Max(indexCL, indexIF); if (index != -1 && semi.size() > index + 1) { ITokenCollection local = Factory.create(); // local semiExp with tokens for type and name if (indexC > 0) { local.add(semi[index]).add(semi[indexC + 1]); } // else if(indexST > 0) // local.add(semi[index]).add(semi[indexST - 1]); else { local.add(semi[index]).add(semi[index + 1]); } doActions(local); return(true); } else if (indexCM != -1 && (indexCM - 2 > -1) && semi.size() > indexCM + 1) { string[] ignore = new string[] { "bool", "sbyte", "short", "int", "long", "byte", "ushort", "uint", "ulong", "double", "char", "decimal", "string", "using" }; if (!ignore.Contains(semi[indexCM - 2])) { ITokenCollection local = Factory.create(); local.add(semi[indexCM - 1]).add(semi[indexCM - 2]); doActions(local); return(true); } } return(false); }
public void RemoveRange(ITokenCollection tokens) { if (tokens == null) { throw new ArgumentNullException("tokens"); } foreach (object obj2 in tokens) { base.List.Remove(obj2); } }
public ITokenCollection Eval(ITokenCollection marking) { return marking; }
public bool IsEnabled(ITokenCollection tokens) { return true; }
/// <summary> /// returns the label and icon of the token collection /// </summary> /// <param name="arg"></param> /// <returns></returns> private static dynamic GetTokenLabelAndIcon(ITokenCollection<IToken> arg) { dynamic ret = new ExpandoObject(); ret.Label = arg.GetCollectionLabel(); ret.Icon = arg.SitecoreIcon; if (string.IsNullOrWhiteSpace(ret.Icon)) ret.Icon = "Office/32x32/package.png"; return ret; }