Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        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));
        }
Exemple #5
0
        private LexicalScope BuildNamespaceScope(NamespaceName nsName, LexicalScope containingScope)
        {
            var ns = namespaces[nsName];

            return(NestedScope.Create(containingScope, ns.SymbolsInPackage, ns.NestedSymbolsInPackage));
        }