public override void Define(SymbolKindEnum kind, string name, ExprOp exprOp) { if (Parent != null) { Parent.Define(kind, name, exprOp); } }
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); }
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)); }
public override ExprOp Lookup(SymbolKindEnum kind, string name) { if (Parent != null) { return(Parent.Lookup(kind, name)); } return(null); }
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); }
/// <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; }
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)); } }
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)); }
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)); }
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]); }
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); }
public override ExprOp Lookup(SymbolKindEnum kind, string name) { LookupCalls.Add(new Tuple <SymbolKindEnum, string>(kind, name)); return(LookupResult); }
public override void Define(SymbolKindEnum kind, string name, ExprOp exprOp) { DefineCalls.Add(new Tuple <SymbolKindEnum, string, ExprOp>(kind, name, exprOp)); }
public override ExprOp Lookup(SymbolKindEnum kind, string name) { return(LookupItems.Lookup(kind, name, this) ?? base.Lookup(kind, name)); }
public override ExprOp Lookup(SymbolKindEnum kind, string name) { return(GrandChild.Lookup(kind, name) ?? base.Lookup(kind, name)); }
public override void Define(SymbolKindEnum kind, string name, ExprOp exprOp) { Parent.Define(kind, name, exprOp); GrandChild.Define(kind, name, exprOp); }
public override ExprOp Lookup(SymbolKindEnum kind, string name) { return(null); }
public override ExprOp Lookup(SymbolKindEnum kind, string name) { throw new NotImplementedException(); }
public virtual void Define(SymbolKindEnum kind, string name, ExprOp exprOp) { }
public abstract ExprOp Lookup(SymbolKindEnum kind, string name);
public Symbol(SymbolKindEnum kind, string name, ExprOp definition) : this() { Kind = kind; Name = name; Definition = definition; }
public override void Define(SymbolKindEnum kind, string name, ExprOp exprOp) { Symbol symbol = new Symbol(kind, name, exprOp); Symbols[symbol] = exprOp; }