Exemplo n.º 1
0
        /// <remarks>
        /// It wouldn't make sense to get all declarations including non-member because
        /// that includes namespace declarations. However, some namespaces come from
        /// the implicit namespace of a compilation unit or are implicitly declared,
        /// so it wouldn't give a full list of the namespaces.
        /// </remarks>
        private static IEnumerable <IEntityDeclarationSyntax> GetEntityDeclarations(
            FixedSet <ICompilationUnitSyntax> compilationUnits)
        {
            var declarations = new Queue <IDeclarationSyntax>();

            declarations.EnqueueRange(compilationUnits.SelectMany(cu => cu.Declarations));
            while (declarations.TryDequeue(out var declaration))
            {
                switch (declaration)
                {
                default:
                    throw ExhaustiveMatch.Failed(declaration);

                case IMemberDeclarationSyntax syn:
                    yield return(syn);

                    break;

                case IFunctionDeclarationSyntax syn:
                    yield return(syn);

                    break;

                case INamespaceDeclarationSyntax syn:
                    declarations.EnqueueRange(syn.Declarations);
                    break;

                case IClassDeclarationSyntax syn:
                    yield return(syn);

                    declarations.EnqueueRange(syn.Members);
                    break;
                }
            }
        }
Exemplo n.º 2
0
 public PackageSyntax(
     Name name,
     FixedSet <ICompilationUnitSyntax> compilationUnits,
     FixedDictionary <Name, PackageIL> references)
 {
     Symbol                = new PackageSymbol(name);
     SymbolTree            = new SymbolTreeBuilder(Symbol);
     CompilationUnits      = compilationUnits;
     AllEntityDeclarations = GetEntityDeclarations(CompilationUnits).ToFixedSet();
     References            = references;
     SymbolTrees           = new SymbolForest(Primitive.SymbolTree, SymbolTree, ReferencedPackages.Select(p => p.SymbolTree));
     Diagnostics           = new Diagnostics(CompilationUnits.SelectMany(cu => cu.Diagnostics));
 }