/// <summary> /// Leaves the current Symbol context and switches to the last context /// </summary> public String ExitContext() { string currid = current.Id; current = path.Pop(); return(currid); }
/// <summary> /// </summary> public void Reset() { current = root; path = new Stack <SymbolContext <SymbolT, CtxKey> >(1024); DefaultContextTraverser = null; ident = ""; }
/// <summary> /// Returns shallow copy of context without the parents or children /// </summary> internal SymbolContext <T, CtxKey> Copy() { var ctx = new SymbolContext <T, CtxKey>(Id, Key, allowShadowing); ctx.lastInserted = lastInserted; ctx.symbols = symbols; return(ctx); }
internal SymbolContext <iT> Clone() { var ctx = new SymbolContext <iT>(id, allowShadowing); ctx.lastInserted = lastInserted; ctx.symbols = new Dictionary <String, iT>(symbols); return(ctx); }
/// <summary> /// Destroy the current Symbol context and pop it from the stack /// </summary> public String Pop() { string ret = contexts.Peek().id; contexts.Pop(); current = contexts.Peek(); return(ret); }
/// <summary> /// Create a new child Symbol context and enters it /// </summary> public void CreateParentContext(string id = null, CtxKey key = default(CtxKey), bool shadowing = true) { var ctx = new SymbolContext <SymbolT, CtxKey>(id, key, shadowing); current.AddParent(ctx); numContexts++; EnterContext(ctx); }
/// <summary> /// Create a new Symbol context and push it onto the stack /// </summary> public void Push(string id = null, bool shadowing = true) { current = new SymbolContext <T>(id, shadowing); contexts.Push(current); if (!shadowing) { allAllowShadowing = false; } }
String OutputGraph(TraverseFunc traverseFunc, SymbolContext <SymbolT, CtxKey> ctx, int depth, int maxh, bool symbs) { string text = (symbs ? ctx.ListContext() : ctx.ToString()); text = String.Concat(Enumerable.Repeat(" ", depth)) + text + Environment.NewLine; if (maxh > 0) { foreach (var p in traverseFunc(ctx)) { text += OutputGraph(traverseFunc, p, depth + 1, maxh - 1, symbs); } } return(text); }
/// <summary> /// Clones context without the parents or children /// </summary> internal SymbolContext <T, CtxKey> Clone(Func <T, bool> pred) { var ctx = new SymbolContext <T, CtxKey>(Id, Key, allowShadowing); ctx.lastInserted = lastInserted; ctx.symbols = new Multimap <string, T>(symbols.Count); foreach (var s in symbols.KeyValueSet) { if (pred(s.Value)) { ctx.symbols.Add(s.Key, s.Value); } } return(ctx); }
/// <summary> /// Recursive DFS from bottom to top (children to parents). /// (takes each parent in depth) /// </summary> internal IEnumerable <SymbolT> LookupRec(SymbolContext <SymbolT, CtxKey> ctx, String symbName) { var t = ctx.LookupAll(symbName); if (t != null) { return(t); } foreach (var p in ctx.parents) { if ((t = LookupRec(p, symbName)) != null) { return(t); } } return(null); }
/// <summary> /// Co-routine/generator to enter each context in each, by enumerating all /// Return value should be discarded /// </summary> internal IEnumerable <bool> GenEnterContexts(SymbolContext <SymbolT, CtxKey> ctx) { foreach (var child in ctx.children) { ident += " "; Debug(ident + "Loaded " + child); EnterContext(child); yield return(true); foreach (var c in GenEnterContexts(child)) { yield return(c); } ExitContext(); Debug(ident + "Exited " + child + " back to " + current); ident = ident.Substring(0, ident.Length - 2); yield return(false); } }
IEnumerable <SymbolT> LookupRec(SymbolContext <SymbolT, CtxKey> ctx, String symbName, CtxKey key) { IEnumerable <SymbolT> t; if (ReferenceEquals(ctx.Key, key)) { if ((t = ctx.LookupAll(symbName)) != null) { return(t); } } foreach (var p in ctx.parents) { if ((t = LookupRec(p, symbName)) != null) { return(t); } } return(null); }
/// <summary> /// Import external context. To load used/imported units /// </summary> internal void ImportUsedContext(SymbolContext <Declaration, Section> ctx) { ctx.allowShadowing = true; Debug("IMPORT CONTEXT " + ctx.Id); symEnv.ImportParentCtxToFirst(ctx); }
/// <summary> /// Import external child context and enters it /// </summary> internal void ImportContext(SymbolContext <SymbolT, CtxKey> ctx) { current.AddChild(ctx); numContexts++; EnterContext(ctx); }
/// <summary> /// Import external parent context to maximum precedence, and enters it /// </summary> internal void ImportParentCtxToFirst(SymbolContext <SymbolT, CtxKey> ctx) { current.parents.Insert(0, ctx); numContexts++; EnterContext(ctx); }
/// <summary> /// Import external parent context to lowest precedence, and enters it /// </summary> internal void ImportParentCtxToLast(SymbolContext <SymbolT, CtxKey> ctx) { current.AddParent(ctx); numContexts++; EnterContext(ctx); }
/// <summary> /// Enters the context passed as argument /// </summary> internal string EnterContext(SymbolContext <SymbolT, CtxKey> ctx) { path.Push(current); current = ctx; return(ctx.Id); }
public SymbolGraph() { root = new SymbolContext <SymbolT, CtxKey>("initial: empty default context"); Reset(); }
internal void AddChild(SymbolContext <T, CtxKey> child) { child.parents.Add(this); children.Add(child); }
internal void AddParent(SymbolContext <T, CtxKey> parent) { parents.Add(parent); parent.children.Add(this); }