コード例 #1
0
        public Task <Package> CompilePackageAsync(
            string name,
            IEnumerable <ICodeFileSource> fileSources,
            FixedDictionary <string, Task <Package> > references,
            TaskScheduler taskScheduler)
        {
            var lexer      = new Lexer();
            var parser     = new CompilationUnitParser();
            var parseBlock = new TransformBlock <ICodeFileSource, CompilationUnitSyntax>(
                async(fileSource) =>
            {
                var file    = await fileSource.LoadAsync();
                var context = new ParseContext(file, new Diagnostics());
                var tokens  = lexer.Lex(context).WhereNotTrivia();
                return(parser.Parse(tokens));
            }, new ExecutionDataflowBlockOptions()
            {
                TaskScheduler = taskScheduler,
                EnsureOrdered = false,
            });

            foreach (var fileSource in fileSources)
            {
                parseBlock.Post(fileSource);
            }

            parseBlock.Complete();

            throw new NotImplementedException();
        }
コード例 #2
0
 public Task <PackageIL> CompilePackageAsync(
     Name name,
     IEnumerable <ICodeFileSource> files,
     FixedDictionary <Name, Task <PackageIL> > referenceTasks)
 {
     return(CompilePackageAsync(name, files, referenceTasks, TaskScheduler.Default));
 }
コード例 #3
0
 public VariableFlags(
     FixedDictionary <BindingSymbol, int> symbolMap,
     BitArray flags)
 {
     this.symbolMap = symbolMap;
     this.flags     = flags;
 }
コード例 #4
0
 public Task <Package> CompilePackageAsync(
     string name,
     IEnumerable <ICodeFileSource> files,
     FixedDictionary <string, Task <Package> > references)
 {
     return(CompilePackageAsync(name, files, references, TaskScheduler.Default));
 }
コード例 #5
0
        public PackageIL CompilePackage(
            string name,
            IEnumerable <CodeFile> files,
            FixedDictionary <Name, PackageIL> references)
        {
            var lexer            = new Lexer();
            var parser           = new CompilationUnitParser();
            var compilationUnits = files
                                   .Select(file =>
            {
                var context = new ParseContext(file, new Diagnostics());
                var tokens  = lexer.Lex(context).WhereNotTrivia();
                return(parser.Parse(tokens));
            })
                                   .ToFixedSet();
            var packageSyntax = new PackageSyntax(name, compilationUnits, references);

            var analyzer = new SemanticAnalyzer()
            {
                SaveLivenessAnalysis   = SaveLivenessAnalysis,
                SaveReachabilityGraphs = SaveReachabilityGraphs,
            };

            return(analyzer.Check(packageSyntax));
        }
コード例 #6
0
 public LexicalScopesBuilderWalker(
     NestedScope globalScope,
     FixedDictionary <NamespaceName, Namespace> namespaces)
 {
     this.globalScope = globalScope;
     this.namespaces  = namespaces;
 }
コード例 #7
0
        public VariableFlags(IExecutableDeclaration declaration, ISymbolTree symbolTree, bool defaultValue)
        {
            var invocableSymbol = declaration.Symbol;

            symbolMap = symbolTree.Children(invocableSymbol).Cast <BindingSymbol>().Enumerate().ToFixedDictionary();
            flags     = new BitArray(symbolMap.Count, defaultValue);
        }
コード例 #8
0
 public PackageIL CompilePackage(
     string name,
     IEnumerable <ICodeFileSource> fileSources,
     FixedDictionary <Name, PackageIL> references)
 {
     return(CompilePackage(name, fileSources.Select(s => s.Load()), references));
 }
コード例 #9
0
 private static FixedList <ISymbol> GetAllSymbols(
     PackageSyntax packageSyntax,
     FixedDictionary <string, Package> references)
 {
     return(references.Values
            .SelectMany(p => p.Declarations.Where(d => !d.IsMember))
            .Concat(packageSyntax.CompilationUnits.SelectMany(GetAllNonMemberDeclarations))
            .ToFixedList());
 }
コード例 #10
0
 public SymbolForest(PrimitiveSymbolTree primitiveSymbolTree, SymbolTreeBuilder symbolTreeBuilder, IEnumerable <FixedSymbolTree> packageTrees)
 {
     if (symbolTreeBuilder.Package is null)
     {
         throw new ArgumentException("Can't be builder for primitive symbols", nameof(symbolTreeBuilder));
     }
     PrimitiveSymbolTree = primitiveSymbolTree;
     this.packageTrees   = packageTrees.Append <ISymbolTree>(symbolTreeBuilder).ToFixedDictionary(t => t.Package !);
 }
コード例 #11
0
 public LexicalScopesBuilder(
     Diagnostics diagnostics,
     PackageSyntax packageSyntax,
     FixedDictionary <string, Package> references)
 {
     this.diagnostics = diagnostics;
     allSymbols       = GetAllSymbols(packageSyntax, references);
     globalScope      = new GlobalScope(GetAllGlobalSymbols(), allSymbols);
 }
コード例 #12
0
 public FixedSymbolTree(PackageSymbol package, FixedDictionary <Symbol, FixedSet <Symbol> > symbolChildren)
 {
     if (symbolChildren.Keys.Any(s => s.Package != package))
     {
         throw new ArgumentException("Children must be for this package", nameof(symbolChildren));
     }
     Package             = package;
     this.symbolChildren = symbolChildren;
 }
コード例 #13
0
 public void Fixed()
 {
     foreach (var(t, p) in TestData.TypeNames.Take(1))
     {
         var items = p.Select(x => new KeyValuePair <string, string>(x, x));
         var d     = new FixedDictionary <string, string, StringComparer>(items);
         Bench(items, allKeys.Except(p), d);
     }
 }
コード例 #14
0
        public static SortedList <string, uint> GetEffectHandleList(EffectResource resource)
        {
            EffectResource.VisualEffectNameList handleList = resource.VisualEffectNames;
            int count = handleList.Count;
            FixedDictionary <string, uint> fd = new FixedDictionary <string, uint>(count);

            for (int i = 0; i < count; i++)
            {
                fd.SetValue(i, handleList[i].EffectName, handleList[i].Index);
            }
            return(new SortedList <string, uint>(fd));
        }
コード例 #15
0
        public async Task <PackageIL> CompilePackageAsync(
            Name name,
            IEnumerable <ICodeFileSource> fileSources,
            FixedDictionary <Name, Task <PackageIL> > referenceTasks,
            TaskScheduler taskScheduler)
        {
            var lexer      = new Lexer();
            var parser     = new CompilationUnitParser();
            var parseBlock = new TransformBlock <ICodeFileSource, ICompilationUnitSyntax>(
                async(fileSource) =>
            {
                var file    = await fileSource.LoadAsync().ConfigureAwait(false);
                var context = new ParseContext(file, new Diagnostics());
                var tokens  = lexer.Lex(context).WhereNotTrivia();
                return(parser.Parse(tokens));
            }, new ExecutionDataflowBlockOptions()
            {
                TaskScheduler = taskScheduler,
                EnsureOrdered = false,
            });

            foreach (var fileSource in fileSources)
            {
                parseBlock.Post(fileSource);
            }

            parseBlock.Complete();

            await parseBlock.Completion.ConfigureAwait(false);

            if (!parseBlock.TryReceiveAll(out var compilationUnits))
            {
                throw new Exception("Not all compilation units are ready");
            }

            var referencePairs = await Task
                                 .WhenAll(referenceTasks.Select(async kv =>
                                                                (alias: kv.Key, package: await kv.Value.ConfigureAwait(false))))
                                 .ConfigureAwait(false);

            var references = referencePairs.ToFixedDictionary(r => r.alias, r => r.package);

            // TODO add the references to the package syntax
            var packageSyntax = new PackageSyntax(name, compilationUnits.ToFixedSet(), references);

            var analyzer = new SemanticAnalyzer()
            {
                SaveLivenessAnalysis   = SaveLivenessAnalysis,
                SaveReachabilityGraphs = SaveReachabilityGraphs,
            };

            return(analyzer.Check(packageSyntax));
        }
コード例 #16
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));
 }
コード例 #17
0
 public Package(
     FixedList <INonMemberDeclaration> nonMemberDeclarations,
     FixedSymbolTree symbolTree,
     Diagnostics diagnostics,
     FixedDictionary <Name, PackageIL> references)
 {
     AllDeclarations       = GetAllDeclarations(nonMemberDeclarations).ToFixedList();
     NonMemberDeclarations = nonMemberDeclarations;
     SymbolTree            = symbolTree;
     Diagnostics           = diagnostics;
     References            = references;
     SymbolTrees           = new SymbolForest(Primitive.SymbolTree, ReferencedPackages.Select(p => p.SymbolTree).Append(SymbolTree));
 }
コード例 #18
0
 public Namespace(
     NamespaceName name,
     FixedDictionary <TypeName, FixedSet <IPromise <Symbol> > > symbols,
     FixedDictionary <TypeName, FixedSet <IPromise <Symbol> > > nestedSymbols,
     FixedDictionary <TypeName, FixedSet <IPromise <Symbol> > > symbolsInPackage,
     FixedDictionary <TypeName, FixedSet <IPromise <Symbol> > > nestedSymbolsInPackage)
 {
     Name                   = name;
     Symbols                = symbols;
     NestedSymbols          = nestedSymbols;
     SymbolsInPackage       = symbolsInPackage;
     NestedSymbolsInPackage = nestedSymbolsInPackage;
 }
コード例 #19
0
        public static void Transform(
            FixedList <MemberDeclarationSyntax> memberDeclarations,
            FixedDictionary <FunctionDeclarationSyntax, LiveVariables> liveness)
        {
            var inserter = new DeleteInserter();

            foreach (var function in memberDeclarations.OfType <FunctionDeclarationSyntax>())
            {
                if (liveness.TryGetValue(function, out var functionLiveness))
                {
                    inserter.Transform(function, functionLiveness);
                }
            }
        }
コード例 #20
0
        public Package Analyze(
            PackageSyntax packageSyntax,
            FixedDictionary <string, Package> references)
        {
            // First pull over all the lexer and parser errors from the compilation units
            var diagnostics = AllDiagnostics(packageSyntax);

            var scopesBuilder = new LexicalScopesBuilder(diagnostics, packageSyntax, references);

            scopesBuilder.BuildScopesInPackage(packageSyntax);

            // Make a list of all the member declarations (i.e. not namespaces)
            var memberDeclarations = packageSyntax.CompilationUnits
                                     .SelectMany(cu => cu.AllMemberDeclarations).ToFixedList();

            // TODO we can't do full type checking without some IL gen and code execution, how to handle that?

            // Do type checking
            TypeResolver.Check(memberDeclarations, diagnostics);

#if DEBUG
            TypeResolutionValidator.Validate(memberDeclarations);
            // TODO validate that all ReferencedSymbols lists have a single value non-errored code
#endif
            MoveChecker.Check(memberDeclarations, diagnostics);

            ShadowChecker.Check(memberDeclarations, diagnostics);

            // TODO we need to check definite assignment as part of this
            BindingMutabilityChecker.Check(memberDeclarations, diagnostics);

            // --------------------------------------------------
            // This is where the representation transitions to IR
            ControlFlowAnalyzer.BuildGraphs(memberDeclarations);
            // --------------------------------------------------

            var liveness = LivenessAnalyzer.Analyze(memberDeclarations);

            DeleteInserter.Transform(memberDeclarations, liveness);

            BorrowChecker.Check(memberDeclarations, diagnostics);

            // Build final declaration objects and find the entry point
            var declarationBuilder = new DeclarationBuilder();
            var declarations       = declarationBuilder.Build(memberDeclarations);
            var entryPoint         = DetermineEntryPoint(declarations, diagnostics);

            return(new Package(packageSyntax.Name, diagnostics.Build(), references, declarations, entryPoint));
        }
コード例 #21
0
        public Package CompilePackage(
            string name,
            IEnumerable <CodeFile> files,
            FixedDictionary <string, Package> references)
        {
            var lexer            = new Lexer();
            var parser           = new CompilationUnitParser();
            var compilationUnits = files
                                   .Select(file =>
            {
                var context = new ParseContext(file, new Diagnostics());
                var tokens  = lexer.Lex(context).WhereNotTrivia();
                return(parser.Parse(tokens));
            })
                                   .ToFixedList();
            var packageSyntax = new PackageSyntax(name, compilationUnits);

            var analyzer = new SemanticAnalyzer();

            return(analyzer.Analyze(packageSyntax, references));
        }
コード例 #22
0
 public PackagesScope(PackageSymbol currentPackage, FixedDictionary <Name, PackageSymbol> packageAliases)
 {
     CurrentPackage      = currentPackage;
     this.packageAliases = packageAliases;
 }
コード例 #23
0
 public SymbolForest(PrimitiveSymbolTree primitiveSymbolTree, IEnumerable <FixedSymbolTree> packageTrees)
 {
     PrimitiveSymbolTree = primitiveSymbolTree;
     this.packageTrees   = packageTrees.ToFixedDictionary(t => t.Package !, t => (ISymbolTree)t);
 }
コード例 #24
0
 public PrimitiveSymbolTree(FixedDictionary <Symbol, FixedSet <Symbol> > symbolChildren)
 {
     this.symbolChildren = symbolChildren;
     GlobalSymbols       = symbolChildren.Keys.Where(s => s.ContainingSymbol is null).ToFixedSet();
 }
コード例 #25
0
 static TokenTypes()
 {
     KeywordFactories = BuildKeywordFactories();
 }
コード例 #26
0
        private void button15_Click(object sender, EventArgs e)
        {
            FixedDictionary dictionary = new FixedDictionary(folderTextBox.Text, 100);

            Console.WriteLine(dictionary);
        }