示例#1
0
        /// <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);
        }
示例#2
0
 /// <summary>
 /// </summary>
 public void Reset()
 {
     current = root;
     path    = new Stack <SymbolContext <SymbolT, CtxKey> >(1024);
     DefaultContextTraverser = null;
     ident = "";
 }
示例#3
0
        /// <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);
        }
示例#4
0
            internal SymbolContext <iT> Clone()
            {
                var ctx = new SymbolContext <iT>(id, allowShadowing);

                ctx.lastInserted = lastInserted;
                ctx.symbols      = new Dictionary <String, iT>(symbols);
                return(ctx);
            }
示例#5
0
        /// <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);
        }
示例#6
0
        /// <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);
        }
示例#7
0
 /// <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;
     }
 }
示例#8
0
        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);
        }
示例#9
0
        /// <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);
        }
示例#10
0
        /// <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);
        }
示例#11
0
        /// <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);
            }
        }
示例#12
0
        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);
        }
示例#13
0
 /// <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);
 }
示例#14
0
 /// <summary>
 /// Import external child context and enters it
 /// </summary>
 internal void ImportContext(SymbolContext <SymbolT, CtxKey> ctx)
 {
     current.AddChild(ctx);
     numContexts++;
     EnterContext(ctx);
 }
示例#15
0
 /// <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);
 }
示例#16
0
 /// <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);
 }
示例#17
0
 /// <summary>
 /// Enters the context passed as argument
 /// </summary>
 internal string EnterContext(SymbolContext <SymbolT, CtxKey> ctx)
 {
     path.Push(current);
     current = ctx;
     return(ctx.Id);
 }
示例#18
0
 public SymbolGraph()
 {
     root = new SymbolContext <SymbolT, CtxKey>("initial: empty default context");
     Reset();
 }
示例#19
0
 internal void AddChild(SymbolContext <T, CtxKey> child)
 {
     child.parents.Add(this);
     children.Add(child);
 }
示例#20
0
 internal void AddParent(SymbolContext <T, CtxKey> parent)
 {
     parents.Add(parent);
     parent.children.Add(this);
 }