public void BuildScope(CodeScope scope) { if (scope != null) { this.Scope = scope; } else if (this.ParentNode != null) { this.Scope = this.ParentNode.OwningScope ?? this.ParentNode.Scope; } else { this.Scope = null; } if (this.ContainScope) { this.OwningScope = new CodeScope(this.Scope, this); } else { this.OwningScope = null; } if (this.Scope != null) { FillScope(this.Scope.ScopeNodes); } foreach (var node in this.Nodes) { node.BuildScope(null); } }
public CodeNode Find(string index) { CodeScope scope = this; while (scope != null) { CodeNode node = scope.ScopeNodes[index]; if (node == null && scope.ExtraScopes != null) { node = scope.ExtraScopes.Select(s => s.Find(index)).Where(n => n != null).FirstOrDefault(); } if (node == null) { scope = scope.ParentScope; } else { return(node); } } return(null); }
public List <CodeNode> FindAllDistinct() { List <CodeNode> nodes = new List <CodeNode>(); HashSet <string> names = new HashSet <string>(); CodeScope scope = this; while (scope != null) { foreach (CodeScope currentScope in new CodeScope[] { scope }.Concat(scope.ExtraScopes == null ? new CodeScope[] { } : scope.ExtraScopes)) { foreach (string key in currentScope.ScopeNodes.Keys) { if (!names.Contains(key)) { names.Add(key); nodes.Add(currentScope.ScopeNodes[key]); } } } scope = scope.ParentScope; } return(nodes); }
internal CodeScope(CodeScope parentScope, CodeNode scopeOwner) { this.ParentScope = parentScope; this.ScopeOwner = scopeOwner; this.ScopeNodes = new CodeNodeCollection(); }