public IReadOnlyDictionary <SyntaxNode, Binder> Build(DiagnosticsBuilder diagnostics)
        {
            var binders = new Dictionary <SyntaxNode, Binder>();
            // The package binder doesn't go in the binders collection, it just serves as the root binder
            var packageBinder = new PackageBinder(package);

            foreach (var compilationUnit in package.Syntax.CompilationUnits)
            {
                new CompilationUnitBindersBuilder(binders, package, compilationUnit, diagnostics).Build(packageBinder);
            }

            return(binders);
        }
        public CompilationUnitBindersBuilder(
            Dictionary <SyntaxNode, Binder> binders,
            Package package,
            CompilationUnitSyntax compilationUnit,
            DiagnosticsBuilder diagnostics)
        {
            Requires.NotNull(binders, nameof(binders));
            Requires.NotNull(package, nameof(package));
            Requires.NotNull(compilationUnit, nameof(compilationUnit));
            Requires.NotNull(diagnostics, nameof(diagnostics));

            this.binders         = binders;
            this.package         = package;
            this.compilationUnit = compilationUnit;
            this.diagnostics     = diagnostics;
        }
        private PackageSyntax(string name, bool isApp, IReadOnlyList <CompilationUnitSyntax> compilationUnits, IReadOnlyList <PackageReferenceSyntax> dependencies)
        {
            Requires.NotNullOrEmpty(name, nameof(name));
            Requires.That(dependencies.Select(d => d.AliasName).Distinct().Count() == dependencies.Count, nameof(dependencies), "Dependency names/alias must be unique");

            Name             = name;
            CompilationUnits = compilationUnits;
            Dependencies     = dependencies;
            IsApp            = isApp;
            var diagnostics = new DiagnosticsBuilder();

            foreach (var compilationUnit in CompilationUnits)
            {
                diagnostics.Add(compilationUnit.Diagnostics);
            }

            Diagnostics = diagnostics.Complete();
        }
Beispiel #4
0
        public Package Build()
        {
            var diagnostics = new DiagnosticsBuilder(packageSyntax.Diagnostics);
            var package     = new Package(packageSyntax);
            var references  = GetPackageReferences(package);

            package.Add(references);
            var globalDeclarations = new DeclarationBuilder(packageSyntax).Build();

            BuildDeclarations(package.GlobalNamespace, globalDeclarations);
            package.FindEntities();
            package.FindEntryPoints();
            var binders = new BindersBuilder(package).Build(diagnostics);

            // TODO resolve entity types

            Resolve(package, binders);             // use binders to resolve rest of semantic model
            // TODO type check
            // TODO borrow check
            package.Set(diagnostics);
            return(package);
        }
 public void Set(DiagnosticsBuilder diagnostics)
 {
     Diagnostics = diagnostics.Complete();
 }