Exemple #1
0
 public override void Define(SymbolKindEnum kind, string name, ExprOp exprOp)
 {
     if (Parent != null)
     {
         Parent.Define(kind, name, exprOp);
     }
 }
Exemple #2
0
        public ExprOp Lookup(SymbolKindEnum kind, string name, object parent)
        {
            IDictionary <string, ExprOp> items;

            if (LookupKindItems.TryGetValue(kind, out items))
            {
                name = name.Replace('-', '_'); // search optimization
                ExprOp op;
                if (items.TryGetValue(name, out op))
                {
                    return(op);
                }
            }

            Tuple <OptionCollection, IDictionary <Option, ExprOp> > optionItems;

            if (LookupKindOptionItems.TryGetValue(kind, out optionItems))
            {
                Option option = optionItems.Item1.LookupOption(name, parent);
                if (option != null)
                {
                    return(optionItems.Item2[option]);
                }
            }

            return(null);
        }
Exemple #3
0
        public void MakeFunctor(string name, ExprFunc exprFunc, SymbolKindEnum symbol = SymbolKindEnum.FUNCTION)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }
            if (exprFunc == null)
            {
                throw new ArgumentNullException("exprFunc");
            }

            // Search optimization
            if (name.EndsWith("_"))
            {
                name = name.Remove(name.Length - 1);
            }

            IDictionary <string, ExprOp> items = GetOrCreate(symbol);

            ExprOp op;

            if (items.TryGetValue(name, out op))
            {
                throw new InvalidOperationException(String.Format("Functor '{0}' is already defined", name));
            }

            items.Add(name, ExprOp.WrapFunctor(exprFunc));
        }
Exemple #4
0
        public override ExprOp Lookup(SymbolKindEnum kind, string name)
        {
            if (Parent != null)
            {
                return(Parent.Lookup(kind, name));
            }

            return(null);
        }
Exemple #5
0
        private IDictionary <string, ExprOp> GetOrCreate(SymbolKindEnum kind)
        {
            IDictionary <string, ExprOp> items;

            if (!LookupKindItems.TryGetValue(kind, out items))
            {
                items = new Dictionary <string, ExprOp>();
                LookupKindItems.Add(kind, items);
            }
            return(items);
        }
Exemple #6
0
        /// <summary>
        /// Ported from void symbol_scope_t::define
        /// </summary>
        public override void Define(SymbolKindEnum kind, string name, ExprOp exprOp)
        {
            Logger.Current.Debug("scope.symbols", () => String.Format("Defining '{0}' = {1} in {2}", name, exprOp, this));

            if (Symbols == null)
            {
                Symbols = new Dictionary <Symbol, ExprOp>();
            }

            Symbol symbol = new Symbol(kind, name, exprOp);

            Symbols[symbol] = exprOp;
        }
Exemple #7
0
        public override ExprOp Lookup(SymbolKindEnum kind, string name)
        {
            ExprOp expr;
            Symbol symbol = new Symbol(kind, name, null);

            if (Symbols.TryGetValue(symbol, out expr))
            {
                return(expr);
            }
            else
            {
                return(base.Lookup(kind, name));
            }
        }
Exemple #8
0
        public override ExprOp Lookup(SymbolKindEnum kind, string name)
        {
            if (kind != SymbolKindEnum.FUNCTION)
            {
                return(null);
            }

            if (name == "value")
            {
                return(ExprOp.WrapFunctor(GetValue));
            }

            return(base.Lookup(kind, name));
        }
Exemple #9
0
 public override ExprOp Lookup(SymbolKindEnum kind, string name)
 {
     if (Symbols != null)
     {
         Logger.Current.Debug("scope.symbols", () => String.Format("Looking for '{0}' in {1}", name, this));
         ExprOp expr;
         Symbol symbol = new Symbol(kind, name, null);
         if (Symbols.TryGetValue(symbol, out expr))
         {
             Logger.Current.Debug("scope.symbols", () => String.Format("Found '{0}' in {1}", name, this));
             return(expr);
         }
     }
     return(base.Lookup(kind, name));
 }
Exemple #10
0
        public void SymbolScope_Define_AddsSymbolToSymbols()
        {
            MockScope   mockScope   = new MockScope();
            SymbolScope symbolScope = new SymbolScope(mockScope);

            SymbolKindEnum kind   = SymbolKindEnum.FUNCTION;
            string         name   = "the-name";
            ExprOp         exprOp = new ExprOp(OpKindEnum.CONSTANTS);

            symbolScope.Define(kind, name, exprOp);

            Assert.Equal(1, symbolScope.Symbols.Count);
            Assert.Equal(kind, symbolScope.Symbols.First().Key.Kind);
            Assert.Equal(name, symbolScope.Symbols.First().Key.Name);
            Assert.Equal(exprOp, symbolScope.Symbols.First().Key.Definition);
            Assert.Equal(exprOp, symbolScope.Symbols[symbolScope.Symbols.First().Key]);
        }
Exemple #11
0
        public void SymbolScope_Lookup_TriesGetAValueFromSymbols()
        {
            MockScope   mockScope   = new MockScope();
            SymbolScope symbolScope = new SymbolScope(mockScope);

            SymbolKindEnum kind   = SymbolKindEnum.FUNCTION;
            string         name   = "the-name";
            ExprOp         exprOp = new ExprOp(OpKindEnum.CONSTANTS);

            symbolScope.Define(kind, name, exprOp);

            ExprOp result = symbolScope.Lookup(kind, name);

            Assert.Equal(exprOp, result);

            ExprOp result2 = symbolScope.Lookup(SymbolKindEnum.OPTION, "dummy");

            Assert.Equal(mockScope.LookupResult, result2);
        }
Exemple #12
0
 public override ExprOp Lookup(SymbolKindEnum kind, string name)
 {
     LookupCalls.Add(new Tuple <SymbolKindEnum, string>(kind, name));
     return(LookupResult);
 }
Exemple #13
0
 public override void Define(SymbolKindEnum kind, string name, ExprOp exprOp)
 {
     DefineCalls.Add(new Tuple <SymbolKindEnum, string, ExprOp>(kind, name, exprOp));
 }
Exemple #14
0
 public override ExprOp Lookup(SymbolKindEnum kind, string name)
 {
     return(LookupItems.Lookup(kind, name, this) ?? base.Lookup(kind, name));
 }
Exemple #15
0
 public override ExprOp Lookup(SymbolKindEnum kind, string name)
 {
     return(GrandChild.Lookup(kind, name) ?? base.Lookup(kind, name));
 }
Exemple #16
0
 public override void Define(SymbolKindEnum kind, string name, ExprOp exprOp)
 {
     Parent.Define(kind, name, exprOp);
     GrandChild.Define(kind, name, exprOp);
 }
Exemple #17
0
 public override ExprOp Lookup(SymbolKindEnum kind, string name)
 {
     return(null);
 }
Exemple #18
0
 public override ExprOp Lookup(SymbolKindEnum kind, string name)
 {
     throw new NotImplementedException();
 }
Exemple #19
0
 public virtual void Define(SymbolKindEnum kind, string name, ExprOp exprOp)
 {
 }
Exemple #20
0
 public abstract ExprOp Lookup(SymbolKindEnum kind, string name);
Exemple #21
0
 public Symbol(SymbolKindEnum kind, string name, ExprOp definition) : this()
 {
     Kind       = kind;
     Name       = name;
     Definition = definition;
 }
Exemple #22
0
        public override void Define(SymbolKindEnum kind, string name, ExprOp exprOp)
        {
            Symbol symbol = new Symbol(kind, name, exprOp);

            Symbols[symbol] = exprOp;
        }