//--------------< does the element exist in Dict's value >----------------- public bool isExistInValue(string typename, TypeElement elem) { foreach (var v in typeTable[typename]) { if (v.filePath == elem.filePath && v.scopeList.SequenceEqual(elem.scopeList)) { return(true); } } return(false); }
public override void doAction(ITokenCollection semi) { List <string> oriSemi = aliasToFullName(semi); List <List <string> > nspaceCandidates = new List <List <string> >(); List <string> scopeList = new List <string>(); for (int i = 0; i < repo_.stack.count - 1; i++) { if (repo_.stack[i].type == "namespace") { scopeList.Add(repo_.stack[i].name); } } nspaceCandidates.Insert(0, scopeList); if (repo_.usingTable.ContainsKey(semi.filePath)) { List <List <string> > usingClone = new List <List <string> >(); foreach (List <string> usingList in repo_.usingTable[semi.filePath]) { var newUsingList = new List <string>(usingList.Select(x => x.Clone() as string)); usingClone.Add(newUsingList); } nspaceCandidates.AddRange(usingClone); } List <string> nestedScope = new List <string>(); for (int i = 0; i < oriSemi.Count - 1; i++) { nestedScope.Add(oriSemi[i]); // } foreach (List <string> nsCnd in nspaceCandidates) { nsCnd.AddRange(nestedScope); } if (nestedScope.Count != 0) { nspaceCandidates.Add(nestedScope); } TypeElement typeElement = repo_.typeTable.findType(oriSemi[oriSemi.Count - 1], nspaceCandidates); // if (typeElement != null && typeElement.filePath != semi.filePath) { repo_.nodeTable[semi.filePath].addChild(repo_.nodeTable[typeElement.filePath], typeElement.fileName); //Console.WriteLine("\n" + semi); //Console.WriteLine(System.IO.Path.GetFileName(semi.filePath) + " depends on " + typeElement.fileName); } }
public override void doAction(ITokenCollection semi) { Display.displayActions(actionDelegate, "action SaveDeclar"); TypeElement elem; try { // if stack is empty (shouldn't be) pop() will throw exception elem = repo_.stack.pop(); // record ending line count and scope level for (int i = 0; i < repo_.locations.Count; ++i) { TypeElement temp = repo_.locations[i]; if (elem.type == temp.type) { if (elem.name == temp.name) { if ((repo_.locations[i]).endLine == 0) { (repo_.locations[i]).endLine = repo_.semi.lineCount(); (repo_.locations[i]).endScopeCount = repo_.scopeCount; break; } } } } } catch { return; } if (AAction.displaySemi) { Lexer.ITokenCollection local = Factory.create(); local.add(elem.type).add(elem.name); if (local[0] == "control") { return; } 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 } }
//--------------< add an element into the dictionary >----------------- public void add(TypeName typename, TypeElement elem) { if (typeTable.ContainsKey(typename)) { if (!isExistInValue(typename, elem)) { typeTable[typename].Add(elem); } } else { List <TypeElement> temp = new List <TypeElement>(); temp.Add(elem); typeTable.Add(typename, temp); } }
public override void doAction(ITokenCollection semi) { Display.displayActions(actionDelegate, "action SaveDeclar"); TypeElement elem = new TypeElement(); elem.type = semi[0]; // expects type elem.name = semi[1]; // expects name elem.beginLine = repo_.lineCount; elem.endLine = elem.beginLine; elem.beginScopeCount = repo_.scopeCount; elem.endScopeCount = elem.beginScopeCount; if (AAction.displaySemi) { Console.Write("\n line# {0,-5}", repo_.lineCount - 1); Console.Write("entering "); string indent = new string(' ', 2 * repo_.stack.count); Console.Write("{0}", indent); this.display(semi); // defined in abstract action } repo_.locations.Add(elem); }
public override void doAction(ITokenCollection semi) { Display.displayActions(actionDelegate, "action PushStack"); ++repo_.scopeCount; TypeElement elem = new TypeElement(); elem.type = semi[0]; // expects type, i.e., namespace, class, struct, .. elem.name = semi[1]; // expects name elem.beginLine = repo_.semi.lineCount() - 1; elem.endLine = 0; // will be set by PopStack action elem.beginScopeCount = repo_.scopeCount; elem.endScopeCount = 0; // will be set by PopStack action repo_.stack.push(elem); // display processing details if requested 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 } // add starting location if namespace, type, or function if (elem.type == "control" || elem.name == "anonymous") { return; } repo_.locations.Add(elem); }
static void Main(string[] args) { TypeTable typeTable = new TypeTable(); ScopeList scopeList1 = new List <string>() { "namespaceA" }; ScopeList scopeList2 = new List <string>() { "namespaceB" }; ScopeList scopeList3 = new List <string>() { "namespaceC" }; TypeElement elem1 = new TypeElement() { type = "class", name = "classA", fileName = "FileA", scopeList = scopeList1 }; TypeElement elem2 = new TypeElement() { type = "class", name = "classB", fileName = "FileB", scopeList = scopeList2 }; TypeElement elem3 = new TypeElement() { type = "class", name = "classB", fileName = "FileB", scopeList = scopeList2 }; typeTable.add("classA", elem1); typeTable.add("classB", elem2); typeTable.add("classA", elem3); typeTable.show(); List <ScopeList> nspaceCandidates = new List <ScopeList>(); nspaceCandidates.Add(new ScopeList() { "namespaceB" }); nspaceCandidates.Add(new ScopeList() { "namespaceA" }); TypeElement ret = typeTable.findType("classA", nspaceCandidates); Console.WriteLine(); Console.WriteLine("Find classA (candidates is {{namespaceB}, {namespaceA}})"); if (ret != null) { foreach (string scope in ret.scopeList) { Console.WriteLine(scope); } } Console.Read(); }
public override void doAction(ITokenCollection semi) { Display.displayActions(actionDelegate, "action PushStack"); if (semi[0] != "delegate") { ++repo_.scopeCount; } TypeElement elem = new TypeElement(); elem.type = semi[0]; // expects type, i.e., namespace, class, struct, .. if (elem.type != "delegate") { elem.name = semi[1]; // expects name } else { elem.name = semi[2]; // expects name } elem.beginLine = repo_.semi.lineCount() - 1; elem.endLine = 0; // will be set by PopStack action elem.beginScopeCount = repo_.scopeCount; elem.endScopeCount = 0; // will be set by PopStack action elem.filePath = semi.filePath; elem.fileName = Path.GetFileName(elem.filePath); repo_.stack.push(elem); // display processing details if requested 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 } // add starting location if namespace, type, or function List <string> scopeList = new List <string>(); for (int i = 0; i < repo_.stack.count - 1; i++) { scopeList.Add(repo_.stack[i].name); } elem.scopeList = scopeList; if (elem.type != "namespace" && elem.type != "function" && elem.type != "control") { repo_.typeTable.add(elem.name, elem); } if (elem.type == "delegate") { repo_.stack.pop(); } }