Ejemplo n.º 1
0
        public void RelationTable_can_store_one_relation()
        {
            PackedExecution packedExecution = new PackedExecution();

            PackedExecution.Builder packedExecutionBuilder = new PackedExecution.Builder(packedExecution);
            long   hash  = 1;
            string name  = "ShellCommon.Shell.ShellCommon.Shell.Merged.Winmetadata";
            PipId  pipId = packedExecutionBuilder.PipTableBuilder.Add(hash, name, PipType.Process);

            packedExecution.ConstructRelationTables();

            RelationTable <PipId, PipId> relationTable = packedExecution.PipDependencies;

            relationTable.Add(new[] { pipId }.AsSpan());

            XAssert.AreEqual(1, relationTable[pipId].Length);

            ReadOnlySpan <PipId> relations = relationTable[pipId];

            XAssert.AreEqual(pipId, relations[0]);

            RelationTable <PipId, PipId> inverseRelationTable = relationTable.Invert();

            XAssert.AreEqual(1, inverseRelationTable[pipId].Length);
            XAssert.AreEqual(pipId, inverseRelationTable[pipId][0]);
        }
Ejemplo n.º 2
0
        public void RelationTable_can_be_built_unordered()
        {
            PackedExecution packedExecution = new PackedExecution();

            PackedExecution.Builder packedExecutionBuilder = new PackedExecution.Builder(packedExecution);
            long   hash   = 1;
            string name   = "ShellCommon.Shell.ShellCommon.Shell.Merged.Winmetadata";
            PipId  pipId1 = packedExecutionBuilder.PipTableBuilder.Add(hash, name, PipType.Process);
            PipId  pipId2 = packedExecutionBuilder.PipTableBuilder.Add(hash + 1, $"{name}2", PipType.Process);
            PipId  pipId3 = packedExecutionBuilder.PipTableBuilder.Add(hash + 2, $"{name}3", PipType.SealDirectory);
            PipId  pipId4 = packedExecutionBuilder.PipTableBuilder.Add(hash + 3, $"{name}4", PipType.Process);

            packedExecution.ConstructRelationTables();

            RelationTable <PipId, PipId> pipDependencyTable = packedExecution.PipDependencies;

            pipDependencyTable.FillToBaseTableCount();
            pipDependencyTable.AddUnordered(pipId4, new PipId[] { pipId2, pipId3 });
            pipDependencyTable.AddUnordered(pipId3, new PipId[] { pipId1 });
            pipDependencyTable.AddUnordered(pipId2, new PipId[] { pipId1 });

            XAssert.IsTrue(pipDependencyTable.MayBeUnordered);

            CheckRelation(packedExecution, pipId1, pipId2, pipId3, pipId4, pipDependencyTable);
        }
Ejemplo n.º 3
0
 static void Main(string[] args)
 {
     if (args.Length == 0)
     {
         Console.WriteLine("Program parameter: input file path");
     }
     else
     {
         try
         {
             using (var streamReader = File.OpenText(args[0]))
             {
                 var scanner       = new Scanner();
                 var tokenString   = scanner.Scan(streamReader.ReadToEnd());
                 var identifiers   = scanner.identifiers.Keys.Except(Scanner.Keywords);
                 var constants     = scanner.constants.Keys;
                 var relationTable = new RelationTable(identifiers, constants);
                 var tree          = new Parser(relationTable).Parse(tokenString);
                 var codeGenerator = new CodeGenerator();
                 var assembly      = codeGenerator.ColdFire(tree);
                 Console.WriteLine(assembly);
             }
         }
         catch (FileNotFoundException)
         {
             Console.WriteLine("File not found");
         }
     }
Ejemplo n.º 4
0
            /// <nodoc />
            public Builder(PackedExecution packedExecution)
            {
                PackedExecution = packedExecution;

                // these are sorted as much as possible given construction order constraints
                StringTableBuilder              = new PackedTable.StringTable.CachingBuilder(PackedExecution.StringTable);
                PathTableBuilder                = new NameTable.Builder(PackedExecution.PathTable, StringTableBuilder);
                DirectoryTableBuilder           = new DirectoryTable.CachingBuilder(PackedExecution.DirectoryTable, PathTableBuilder);
                FileTableBuilder                = new FileTable.CachingBuilder(PackedExecution.FileTable, PathTableBuilder);
                PipTableBuilder                 = new PipTable.Builder(PackedExecution.PipTable, StringTableBuilder);
                PipExecutionTableBuilder        = new PipExecutionTable.Builder <PipExecutionTable>(PackedExecution.PipExecutionTable);
                ProcessExecutionTableBuilder    = new ProcessExecutionTable.Builder <ProcessExecutionTable>(PackedExecution.ProcessExecutionTable);
                ProcessPipExecutionTableBuilder = new ProcessPipExecutionTable.Builder <ProcessPipExecutionTable>(PackedExecution.ProcessPipExecutionTable);
                PipTableBuilder                 = new PipTable.Builder(PackedExecution.PipTable, StringTableBuilder);
                WorkerTableBuilder              = new WorkerTable.CachingBuilder(PackedExecution.WorkerTable, StringTableBuilder);

                if (packedExecution.ConsumedFiles != null)
                {
                    ConsumedFilesBuilder = new RelationTable <PipId, FileId> .Builder(packedExecution.ConsumedFiles);

                    DeclaredInputDirectoriesBuilder = new RelationTable <PipId, DirectoryId> .Builder(packedExecution.DeclaredInputDirectories);

                    DeclaredInputFilesBuilder = new RelationTable <PipId, FileId> .Builder(packedExecution.DeclaredInputFiles);

                    DirectoryContentsBuilder = new RelationTable <DirectoryId, FileId> .Builder(packedExecution.DirectoryContents);
                }
            }
Ejemplo n.º 5
0
 static void Main(string[] args)
 {
     if (args.Length == 0)
     {
         MessageBox.Show("Program parameter: input file path", "Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         try
         {
             using (var streamReader = File.OpenText(args[0]))
             {
                 var scanner       = new Scanner();
                 var tokenString   = scanner.Scan(streamReader.ReadToEnd());
                 var identifiers   = scanner.identifiers.Keys.Except(Scanner.Keywords);
                 var constants     = scanner.constants.Keys;
                 var relationTable = new RelationTable(identifiers, constants);
                 var tree          = new Parser(relationTable).Parse(tokenString);
                 Application.Run(new TreeViewer(tree));
             }
         }
         catch (FileNotFoundException)
         {
             MessageBox.Show("File not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
Ejemplo n.º 6
0
        public void RelationTable_can_be_built()
        {
            PackedExecution packedExecution = new PackedExecution();

            PackedExecution.Builder packedExecutionBuilder = new PackedExecution.Builder(packedExecution);
            long   hash   = 1;
            string name   = "ShellCommon.Shell.ShellCommon.Shell.Merged.Winmetadata";
            PipId  pipId  = packedExecutionBuilder.PipTableBuilder.Add(hash, name, PipType.Process);
            PipId  pipId2 = packedExecutionBuilder.PipTableBuilder.Add(hash + 1, $"{name}2", PipType.Process);
            PipId  pipId3 = packedExecutionBuilder.PipTableBuilder.Add(hash + 2, $"{name}3", PipType.Process);

            packedExecution.ConstructRelationTables();

            RelationTable <PipId, PipId> relationTable = packedExecution.PipDependencies;

            RelationTable <PipId, PipId> .Builder builder = new RelationTable <PipId, PipId> .Builder(relationTable);

            // add relations in any order
            builder.Add(pipId3, pipId2);
            builder.Add(pipId3, pipId);
            builder.Add(pipId, pipId3);
            builder.Add(pipId, pipId2);

            // done adding relations; flush to table
            builder.Complete();

            XAssert.AreArraysEqual(new[] { pipId2, pipId3 }, relationTable[pipId].ToArray(), true);
            XAssert.AreArraysEqual(new PipId[0], relationTable[pipId2].ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId, pipId2 }, relationTable[pipId3].ToArray(), true);

            XAssert.AreArraysEqual(new[] { pipId2, pipId3 }, relationTable.Enumerate(pipId).ToArray(), true);
            XAssert.AreArraysEqual(new PipId[0], relationTable.Enumerate(pipId2).ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId, pipId2 }, relationTable.Enumerate(pipId3).ToArray(), true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initialize all the elements of this index, as concurrently as possible.
        /// </summary>
        /// <param name="progressAction">Action called (from an arbitrary Task thread) to report completion of various index parts.</param>
        /// <returns>A task which is complete when the index is fully built.</returns>
        public Task InitializeAsync(Action <string> progressAction)
        {
            // All the things we want to do concurrently to index our data.
            // This is broken out as a separate list since it is useful to run these serially sometimes when debugging
            // (e.g. when the hacky Span sort code you found online starts hitting stack overflows, whereas the .NET 5
            // Span.Sort method just works...).
            List <(string, Action)> actions = new List <(string, Action)>
            {
                ("Sorted strings", () => StringIndex = new StringIndex(PackedExecution.StringTable)),
                ("Indexed pip names", () => PipNameIndex = new NameIndex(PackedExecution.PipTable.PipNameTable)),
                ("Indexed paths", () => PathIndex = new NameIndex(PackedExecution.PathTable)),
                ("Indexed pip dependents", () => PipDependents = PackedExecution.PipDependencies.Invert()),
                ("Indexed file consumers", () => FileConsumers = PackedExecution.ConsumedFiles.Invert()),
                ("Indexed produced files", () => ProducedFiles =
                     RelationTable <FileId, PipId>
                     .FromSingleValueTable(PackedExecution.FileProducer, PackedExecution.PipTable)
                     .Invert()),
                ("Indexed input-file-declaring pips", () => InputFileDeclarers = PackedExecution.DeclaredInputFiles.Invert()),
                ("Indexed input-directory-declaring pips", () => InputDirectoryDeclarers = PackedExecution.DeclaredInputDirectories.Invert()),
                ("Indexed parent directories", () => ParentDirectories = PackedExecution.DirectoryContents.Invert())
            };

            // Concurrently generate all the sorted strings, name indices, and inverse relationships that we need.
            return(Task.WhenAll(
                       actions
                       .Select(tuple => Task.Run(
                                   () =>
            {
                tuple.Item2();
                progressAction(tuple.Item1);
            }))
                       .ToArray()));
        }
Ejemplo n.º 8
0
        public void RelationTable_can_be_built()
        {
            PackedExecution packedExecution = new PackedExecution();

            PackedExecution.Builder packedExecutionBuilder = new PackedExecution.Builder(packedExecution);
            long   hash   = 1;
            string name   = "ShellCommon.Shell.ShellCommon.Shell.Merged.Winmetadata";
            PipId  pipId1 = packedExecutionBuilder.PipTableBuilder.Add(hash, name, PipType.Process);
            PipId  pipId2 = packedExecutionBuilder.PipTableBuilder.Add(hash + 1, $"{name}2", PipType.Process);
            PipId  pipId3 = packedExecutionBuilder.PipTableBuilder.Add(hash + 2, $"{name}3", PipType.SealDirectory);
            PipId  pipId4 = packedExecutionBuilder.PipTableBuilder.Add(hash + 3, $"{name}4", PipType.Process);

            packedExecution.ConstructRelationTables();

            RelationTable <PipId, PipId> relationTable = packedExecution.PipDependencies;

            RelationTable <PipId, PipId> .Builder builder = new RelationTable <PipId, PipId> .Builder(relationTable);

            // add relations in any order (but without cycles)
            // 1 <- 2
            // 1 <- 3
            // 2 <- 4
            // 3 <- 4
            builder.Add(pipId2, pipId1);
            builder.Add(pipId3, pipId1);
            builder.Add(pipId4, pipId2);
            builder.Add(pipId4, pipId3);

            // done adding relations; flush to table
            builder.Complete();

            CheckRelation(packedExecution, pipId1, pipId2, pipId3, pipId4, relationTable);
        }
Ejemplo n.º 9
0
 /// <summary>After the base tables are populated, construct the (now properly sized) relation tables.</summary>
 public void ConstructRelationTables()
 {
     FileProducer             = new SingleValueTable <FileId, PipId>(FileTable);
     ConsumedFiles            = new RelationTable <PipId, FileId>(PipTable, FileTable);
     DeclaredInputDirectories = new RelationTable <PipId, DirectoryId>(PipTable, DirectoryTable);
     DeclaredInputFiles       = new RelationTable <PipId, FileId>(PipTable, FileTable);
     DirectoryContents        = new RelationTable <DirectoryId, FileId>(DirectoryTable, FileTable);
     PipDependencies          = new RelationTable <PipId, PipId>(PipTable, PipTable);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// After the base tables are populated, construct the (now properly sized) relation tables.
        /// </summary>
        public void ConstructRelationTables()
        {
            //System.Diagnostics.ContractsLight.Contract.Requires(ConsumedFiles == null, "Must only construct relation tables once");

            ConsumedFiles            = new RelationTable <PipId, FileId>(PipTable, FileTable);
            DeclaredInputDirectories = new RelationTable <PipId, DirectoryId>(PipTable, DirectoryTable);
            DeclaredInputFiles       = new RelationTable <PipId, FileId>(PipTable, FileTable);
            DirectoryContents        = new RelationTable <DirectoryId, FileId>(DirectoryTable, FileTable);
            PipDependencies          = new RelationTable <PipId, PipId>(PipTable, PipTable);
        }
Ejemplo n.º 11
0
 static void Main(string[] args)
 {
     if (args.Length == 0)
         Console.WriteLine("Program parameter: input file path");
     else
         try
         {
             using (var streamReader = File.OpenText(args[0]))
             {
                 var scanner = new Scanner();
                 var tokenString = scanner.Scan(streamReader.ReadToEnd());
                 var identifiers = scanner.identifiers.Keys.Except(Scanner.Keywords);
                 var constants = scanner.constants.Keys;
                 var relationTable = new RelationTable(identifiers, constants);
                 var tree = new Parser(relationTable).Parse(tokenString);
                 var codeGenerator = new CodeGenerator();
                 var assembly = codeGenerator.ColdFire(tree);
                 Console.WriteLine(assembly);
             }
         }
         catch (FileNotFoundException)
         {
             Console.WriteLine("File not found");
         }
         catch (IOException e)
         {
             Console.WriteLine(e.Message);
         }
         catch (LexicalException e)
         {
             Console.WriteLine(e.Message);
         }
         catch (SyntaxException e)
         {
             Console.WriteLine(e.Message);
         }
         catch (SemanticException e)
         {
             Console.WriteLine(e.Message);
         }
         catch (RelationException<string, Relation> e)
         {
             Console.WriteLine(e.Message);
         }
 }
Ejemplo n.º 12
0
        public void RelationTable_can_store_multiple_relations()
        {
            PackedExecution packedExecution = new PackedExecution();

            PackedExecution.Builder packedExecutionBuilder = new PackedExecution.Builder(packedExecution);
            long   hash   = 1;
            string name   = "ShellCommon.Shell.ShellCommon.Shell.Merged.Winmetadata";
            PipId  pipId  = packedExecutionBuilder.PipTableBuilder.Add(hash, name, PipType.Process);
            PipId  pipId2 = packedExecutionBuilder.PipTableBuilder.Add(hash + 1, $"{name}2", PipType.Process);
            PipId  pipId3 = packedExecutionBuilder.PipTableBuilder.Add(hash + 2, $"{name}3", PipType.Process);

            XAssert.AreNotEqual(pipId, pipId2);
            XAssert.AreNotEqual(pipId, pipId3);
            XAssert.AreNotEqual(pipId2, pipId3);

            packedExecution.ConstructRelationTables();

            RelationTable <PipId, PipId> relationTable = packedExecution.PipDependencies;

            relationTable.Add(new[] { pipId2, pipId3 }.AsSpan());

            XAssert.AreEqual(2, relationTable[pipId].Length);

            ReadOnlySpan <PipId> relations = relationTable[pipId];

            XAssert.AreEqual(pipId2, relations[0]);
            XAssert.AreEqual(pipId3, relations[1]);

            relationTable.Add(new[] { pipId }.AsSpan());

            XAssert.AreEqual(1, relationTable[pipId2].Length);

            relationTable.Add(new[] { pipId, pipId2, pipId3 }.AsSpan());

            XAssert.AreEqual(3, relationTable[pipId3].Length);
            XAssert.AreArraysEqual(new[] { pipId2, pipId3 }, relationTable[pipId].ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId, pipId2, pipId3 }, relationTable[pipId3].ToArray(), true);

            RelationTable <PipId, PipId> inverseRelationTable = relationTable.Invert();

            XAssert.AreArraysEqual(new[] { pipId2, pipId3 }, inverseRelationTable[pipId].ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId, pipId3 }, inverseRelationTable[pipId2].ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId, pipId3 }, inverseRelationTable[pipId3].ToArray(), true);
        }
Ejemplo n.º 13
0
        private static int RecursiveCalculation(Relation relation, int multiply, RelationTable table)
        {
            Console.Write($"{multiply}");
            var sum = 0;

            if (!relation.Children.Any())
            {
                return(multiply);
            }

            Console.Write("*(1+");
            foreach (var(key, value) in relation.Children)
            {
                sum += RecursiveCalculation(table[key], value, table);
            }
            Console.Write(")");

            return(multiply * (sum + 1));
        }
Ejemplo n.º 14
0
 static void Main(string[] args)
 {
     if (args.Length == 0)
         MessageBox.Show("Program parameter: input file path", "Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
     else
         try
         {
             using (var streamReader = File.OpenText(args[0]))
             {
                 var scanner = new Scanner();
                 var tokenString = scanner.Scan(streamReader.ReadToEnd());
                 var identifiers = scanner.identifiers.Keys.Except(Scanner.Keywords);
                 var constants = scanner.constants.Keys;
                 var relationTable = new RelationTable(identifiers, constants);
                 var tree = new Parser(relationTable).Parse(tokenString);
                 Application.Run(new TreeViewer(tree));
             }
         }
         catch (FileNotFoundException)
         {
             MessageBox.Show("File not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         catch (IOException e)
         {
             MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         catch (LexicalException e)
         {
             MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         catch (SyntaxException e)
         {
             MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         catch (RelationException<string, Relation> e)
         {
             MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Create syntax analyser instance
 /// </summary>
 /// <param name="relationTable">Wirth-Weber precedence relationship table</param>
 public Parser(RelationTable relationTable)
 {
     this.relationTable = relationTable;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Create syntax analyser instance
 /// </summary>
 /// <param name="relationTable">Wirth-Weber precedence relationship table</param>
 public Parser(RelationTable relationTable)
 {
     this.relationTable = relationTable;
 }
Ejemplo n.º 17
0
        private static void CheckRelation(PackedExecution packedExecution, PipId pipId1, PipId pipId2, PipId pipId3, PipId pipId4, RelationTable <PipId, PipId> relationTable)
        {
            XAssert.AreArraysEqual(new PipId[0], relationTable[pipId1].ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId1 }, relationTable[pipId2].ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId1 }, relationTable[pipId3].ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId2, pipId3 }, relationTable[pipId4].ToArray(), true);

            XAssert.AreArraysEqual(new PipId[0], relationTable.Enumerate(pipId1).ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId1 }, relationTable.Enumerate(pipId2).ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId2, pipId3 }, relationTable.Enumerate(pipId4).ToArray(), true);

            // try traversing from pipId4; should traverse over pipId3 and reach pipId (as well as pipId2)
            IEnumerable <PipId> reachable = relationTable.Traverse(
                pipId4,
                p => packedExecution.PipTable[p].PipType == PipType.Process
                    ? TraversalFilterResult.AcceptAndHalt
                    : TraversalFilterResult.RejectAndContinue);

            XAssert.AreArraysEqual(new[] { pipId1, pipId2 }, reachable.OrderBy(p => p.Value).ToArray(), true);
        }