public void TestBuildNestedHierarchy() { var names = new[] { "a.b", "a.d.e", "a", "a.b.c", "a.c", "a.B.c", "a.d", "a" }; var errorMock = new ErrorCacheMock(); var scopes = NestedScope.BuildHeirarchy(names, errorMock); errorMock.Count.Should().Be(0); scopes.Count.Should().Be(6); foreach (var pair in scopes) { pair.Value.Name.Should().Be(pair.Key); } var a = scopes["a"]; var ab = scopes["a.b"]; var ac = scopes["a.c"]; var ad = scopes["a.d"]; var abc = scopes["a.b.c"]; var ade = scopes["a.d.e"]; a.IsTopMost.Should().BeTrue(); a.Children.Should().Contain(new[] { ab, ac, ad }); ab.Children.Should().Contain(abc); ad.Children.Should().Contain(ade); }
public void MergeDefaults(string defaultJson, IDictionary <string, NestedScope> existing) { var data = JsonConvert.DeserializeObject <NestedData>(defaultJson); var variables = LoadData(data, Constants.PackageManagerIdentity).ToList(); // Complete the hierarchy and then merge the variables into the hierarchy var scopes = NestedScope.BuildHeirarchy(variables.Select(v => v.PackageId), ErrorCache, existing); foreach (var variable in variables) { var varRef = new VariableRef { PackageId = variable.PackageId, VariableName = variable.Name }; if (scopes[variable.PackageId].TryFindVariable(varRef, out var existingVariable)) { existingVariable.Default = variable.Default; if (existingVariable.Type != variable.Type) { existingVariable.Type = variable.Type; existingVariable.Value = null; } } else { scopes[variable.PackageId].Store(variable); } } }
public ScriptLoaderTests() { scope = new NestedScope(); errorCache = new ErrorCacheMock(); loader = new ScriptLoader { Scope = scope, ErrorCache = errorCache }; scope.Store(new Variable { PackageId = Constants.PackageManagerIdentity, Name = "var1", Default = "1", Type = SupportedTypes.Integer.GetStringValue(), Units = Units.None.GetStringValue() }); scope.Store(new Variable { PackageId = Constants.PackageManagerIdentity, Name = "var_2", Default = "60s", Type = SupportedTypes.String.GetStringValue(), Units = Units.None.GetStringValue() }); }
public void TestConstruction() { var topLevel = new NestedScope(); topLevel.IsTopMost.Should().BeTrue(); topLevel.Parent.Should().BeNull(); topLevel.Children.Should().BeEmpty(); var midLevel = new NestedScope(topLevel); topLevel.IsTopMost.Should().BeTrue(); midLevel.IsTopMost.Should().BeFalse(); topLevel.Parent.Should().BeNull(); midLevel.Parent.Should().BeSameAs(topLevel); topLevel.Children.Should().Contain(midLevel); midLevel.Children.Should().BeEmpty(); var lowLevel = new NestedScope(midLevel); topLevel.IsTopMost.Should().BeTrue(); midLevel.IsTopMost.Should().BeFalse(); lowLevel.IsTopMost.Should().BeFalse(); topLevel.Parent.Should().BeNull(); midLevel.Parent.Should().BeSameAs(topLevel); lowLevel.Parent.Should().BeSameAs(midLevel); topLevel.Children.Should().Contain(midLevel); midLevel.Children.Should().Contain(lowLevel); lowLevel.Children.Should().BeEmpty(); }
public LexicalScopesBuilderWalker( NestedScope globalScope, FixedDictionary <NamespaceName, Namespace> namespaces) { this.globalScope = globalScope; this.namespaces = namespaces; }
public override void Init() { OnInit?.Invoke(NestedScope); base.Init(); SceneManager.activeSceneChanged += ActiveSceneChanged; SceneManager.sceneUnloaded += s => { NestedScope.Save(); }; }
private static NestedScope BuildGlobalScope( PackagesScope packagesScope, Namespace globalNamespace) { var allPackagesGlobalScope = NestedScope.CreateGlobal(packagesScope, globalNamespace.Symbols, globalNamespace.NestedSymbols); return(allPackagesGlobalScope); }
private static LexicalScope BuildBodyScope( IEnumerable <IConstructorParameterSyntax> parameters, LexicalScope containingScope) { var symbols = parameters.OfType <INamedParameterSyntax>() .GroupBy(p => p.Name, p => p.Symbol) .ToFixedDictionary(e => (TypeName)e.Key, e => e.ToFixedSet <IPromise <Symbol> >()); return(NestedScope.Create(containingScope, symbols)); }
public IDictionary <string, NestedScope> LoadFromElastic(IList <Variable> variables, IDictionary <string, NestedScope> existing = null) { var scopes = NestedScope.BuildHeirarchy(variables.Select(v => v.PackageId), ErrorCache, existing); foreach (var variable in variables) { scopes[variable.PackageId].Store(variable); } return(scopes); }
private static LexicalScope BuildClassScope( IClassDeclarationSyntax @class, LexicalScope containingScope) { // Only "static" names are in scope. Other names must use `self.` var symbols = @class.Members.OfType <IAssociatedFunctionDeclarationSyntax>() .GroupBy(m => m.Name, m => m.Symbol) .ToFixedDictionary(e => (TypeName)e.Key, e => e.ToFixedSet <IPromise <Symbol> >()); return(NestedScope.Create(containingScope, symbols)); }
private static LexicalScope BuildVariableScope( LexicalScope containingScope, Name name, IPromise <VariableSymbol> symbol) { var symbols = new Dictionary <TypeName, FixedSet <IPromise <Symbol> > >() { { name, symbol.Yield().ToFixedSet <IPromise <Symbol> >() } }.ToFixedDictionary(); return(NestedScope.Create(containingScope, symbols)); }
private static void AddVariable(NestedScope scope, string name, object value, SupportedTypes type = SupportedTypes.Integer) { var variable = new Variable { PackageId = scope.Name, Name = name, Value = value.ToString(), Type = type.GetStringValue(), Units = Units.None.GetStringValue() }; scope.Store(variable); }
private void ActiveSceneChanged(Scene oldScene, Scene newScene) { if (oldScene.name != null) { NestedScope.Save(); } NestedScope = new T(); OnSceneChange?.Invoke(NestedScope, newScene); (NestedScope as ScopePlayerPrefs)?.Setup(newScene.name); NestedScope.Init(); }
public TimeSeriesSettingsTests() { errorCache = new ErrorCacheMock(); globalScope = new NestedScope { Name = Constants.PackageManagerIdentity }; packageScope = new NestedScope(globalScope) { Name = "TestPackage" }; AddVariable(globalScope, Constants.GlobalSettings.NoOfShards, DefaultShards); AddVariable(globalScope, Constants.GlobalSettings.NoOfReplicas, DefaultReplicas); AddVariable(globalScope, Constants.GlobalSettings.RefreshInterval, DefaultRefreshInterval, SupportedTypes.String); }
private static void BuildScopesInFunctionBody( LexicalScope containingScope, FunctionDeclarationSyntax function, ExpressionLexicalScopesBuilder binder) { var symbols = new List <ISymbol>(); foreach (var parameter in function.Parameters) { symbols.Add(parameter); } containingScope = new NestedScope(containingScope, symbols, Enumerable.Empty <ISymbol>()); binder.VisitBlock(function.Body, containingScope); }
public static NestedScope[] CreateNestedScopes(int depth = 3) { var result = new NestedScope[depth]; NestedScope prev = null; for (int i = 0; i < depth; ++i) { var current = new NestedScope(prev); result[i] = current; prev = current; } return(result); }
private void RecordChanges(NestedScope current, NestedScope original, BulkDescriptor bulk) { var correlation = current.Aspects.CorrelateWith(original?.Aspects); // Ensure all of the current aspects have changes recorded foreach (var tuple in correlation.SourceItems) { tuple.Item.RecordChanges(tuple.PairedWith, bulk); } // Remove any now irrelevant aspects foreach (var aspect in correlation.NonSourceItems) { aspect.Item.RemoveAll(bulk); } }
public const string Stable = "stable"; // data that isn't changing public static IEnumerable <Tuple <string, object> > SettingForLifestage(NestedScope scope, IErrorCache errorCache, bool active) { yield return(Tuple.Create( $"{Constants.IndexRoutingAllocationInclude}{RoleTag}", active ? (object)Active : Stable)); if (active) { yield return(scope.ProvideSetting <int>(Constants.GlobalSettings.NoOfShards, errorCache)); } // MAYBE want to be able to support different values for active and stable ??? yield return(scope.ProvideSetting <int>(Constants.GlobalSettings.NoOfReplicas, errorCache)); yield return(scope.ProvideSetting <string>(Constants.GlobalSettings.RefreshInterval, errorCache)); }
public override void VisitBlock(BlockSyntax block, LexicalScope containingScope) { if (block == null) { return; } foreach (var statement in block.Statements) { VisitStatement(statement, containingScope); // Each variable declaration effectively starts a new scope after it, this // ensures a lookup returns the last declaration if (statement is VariableDeclarationStatementSyntax variableDeclaration) { containingScope = new NestedScope(containingScope, variableDeclaration.Yield(), Enumerable.Empty <ISymbol>()); } } }
public void TestMergeWithExistingHierarchy() { var names = new[] { "a.b", "a.d.e", "a", "a.b.c", "a.c", "a.B.c", "a.d", "a" }; var errorMock = new ErrorCacheMock(); var scopes = NestedScope.BuildHeirarchy(names, errorMock); names = new[] { "a.b", "a.b.c", "a.d.f", "a.z" }; scopes = NestedScope.BuildHeirarchy(names, errorMock, scopes); errorMock.Count.Should().Be(0); scopes.Count.Should().Be(8); foreach (var pair in scopes) { pair.Value.Name.Should().Be(pair.Key); } var a = scopes["a"]; var ab = scopes["a.b"]; var ac = scopes["a.c"]; var ad = scopes["a.d"]; var abc = scopes["a.b.c"]; var ade = scopes["a.d.e"]; var adf = scopes["a.d.f"]; var az = scopes["a.z"]; a.IsTopMost.Should().BeTrue(); a.Children.Should().Contain(new[] { ab, ac, ad, az }); ab.Children.Should().Contain(abc); ad.Children.Should().Contain(new[] { ade, adf }); az.Children.Should().BeEmpty(); }
private LexicalScope BuildUsingDirectivesScope( FixedList <IUsingDirectiveSyntax> usingDirectives, LexicalScope containingScope) { if (!usingDirectives.Any()) { return(containingScope); } var importedSymbols = new Dictionary <TypeName, HashSet <IPromise <Symbol> > >(); foreach (var usingDirective in usingDirectives) { if (!namespaces.TryGetValue(usingDirective.Name, out var ns)) { // TODO diagnostics.Add(NameBindingError.UsingNonExistentNamespace(file, usingDirective.Span, usingDirective.Name)); continue; } foreach (var(name, additionalSymbols) in ns.Symbols) { if (importedSymbols.TryGetValue(name, out var symbols)) { symbols.AddRange(additionalSymbols); } else { importedSymbols.Add(name, additionalSymbols.ToHashSet()); } } } var symbolsInScope = importedSymbols.ToFixedDictionary(e => e.Key, e => e.Value.ToFixedSet()); return(NestedScope.Create(containingScope, symbolsInScope)); }
private LexicalScope BuildNamespaceScope(NamespaceName nsName, LexicalScope containingScope) { var ns = namespaces[nsName]; return(NestedScope.Create(containingScope, ns.SymbolsInPackage, ns.NestedSymbolsInPackage)); }
public void SetOriginalState(NestedScope state) { OriginalState = state; CurrentState = state.Clone(); }
private static Tuple <string, object> ProvideSetting <T>(this NestedScope scope, string settingName, IErrorCache errorCache) { var variable = scope.FirstVarOfName(settingName, errorCache); return(variable.ProvideSetting <T>(settingName, errorCache)); }