public override ISet <Expression> GetKill(BasicBlock block)
 {
     return(SetFactory.GetSet(
                block.Commands
                .OfType <Assignment>()
                .Select(x => x.Target as Expression)));
 }
        public override ISet <Expression> TransferFunction(ISet <Expression> input, BasicBlock block)
        {
            var kill   = GetKill(block).Cast <Identifier>();
            var result = SetFactory.GetSet(
                input.Where(inputExpression =>
                            !kill.Any(inputExpression.HasIdentifiedSubexpression)));

            result.UnionWith(GetGen(block));

            return(result);

            /*
             * Non-LINQ realization
             * var difference = SetFactory.GetSet();
             * var foundInKill = false;
             * foreach (var inputExpression in input)
             * {
             *  foreach (var killExpression in kill)
             *  {
             *      if (!inputExpression.HasIdentifiedSubexpression(killExpression as Identifier))
             *          continue;
             *
             *      foundInKill = true;
             *      break;
             *  }
             *
             *  if (!foundInKill)
             *      difference.Add(inputExpression);
             *
             *  foundInKill = false;
             * }
             * return SetFactory.GetSet(GetGen(block).Union(difference));
             */
        }
Esempio n. 3
0
        public void Should_be_possible_to_evaluate_a_Set_in_the_ObjectType()
        {
            OvalDocumentLoader ovalDocument = new OvalDocumentLoader();

            sc.oval_system_characteristics systemCharacteristics = ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_sets.xml");
            oval_definitions        definitions = ovalDocument.GetFakeOvalDefinitions("definitionsWithSet.xml");
            IEnumerable <StateType> states      = definitions.states;

            set registryObjectSet = SetFactory.GetSetFromDefinitionsOfRegistryObject("definitionsWithSet.xml", "oval:org.mitre.oval:obj:6000");

            SetEvaluator setEvaluator = new SetEvaluator(systemCharacteristics, states, null);
            SetResult    result       = setEvaluator.Evaluate(registryObjectSet);

            Assert.IsNotNull(result, "the items expected is null");
            Assert.AreEqual(3, result.Result.Count(), "the quantity of items is not expected");
            Assert.AreEqual(FlagEnumeration.complete, result.ObjectFlag, "the object flag is not expected");

            string element = result.Result.Where <string>(item => item == "1").SingleOrDefault();

            Assert.IsNotNull(element, "the element expected is not exits");
            element = result.Result.Where <string>(item => item == "2").SingleOrDefault();
            Assert.IsNotNull(element, "the element expected is not exits");
            element = result.Result.Where <string>(item => item == "3").SingleOrDefault();
            Assert.IsNotNull(element, "the element expected is not exits");
        }
        static CorruptionPitBiome()
        {
            SetFactory factory = TileID.Sets.Factory;

            int[] numArray = new int[] { 21, 31, 26 };
            CorruptionPitBiome.ValidTiles = factory.CreateBoolSet(true, numArray);
        }
Esempio n. 5
0
        public static Dictionary <Edge <BasicBlock>, ISet <int> > FindAllNaturalLoops(ControlFlowGraph.Graph g)
        {
            var classify = EdgeClassification.EdgeClassification.ClassifyEdge(g);
            var result   = new Dictionary <Edge <BasicBlock>, ISet <int> >();

            foreach (var pair in classify)
            {
                if (pair.Value == EdgeClassification.Model.EdgeType.Retreating)
                {
                    Stack = new Stack <int>();
                    Loop  = SetFactory.GetSet(new int[] { pair.Key.Target.BlockId });
                    Insert(pair.Key.Source.BlockId);
                    while (Stack.Count() > 0)
                    {
                        int m = Stack.Pop();
                        foreach (BasicBlock p in g.getParents(m))
                        {
                            Insert(p.BlockId);
                        }
                    }
                    result.Add(pair.Key, Loop);
                }
            }
            return(result);
        }
Esempio n. 6
0
        public void Should_be_possible_to_get_child_set_references()
        {
            set setElement = SetFactory.GetSetFromDefinitionsOfRegistryObject("definitionsWithSet.xml", "oval:org.mitre.oval:obj:5000");
            IEnumerable <set> objectReferences = setElement.GetSets();

            Assert.AreEqual(2, objectReferences.Count(), "the number of sets is not expected");
        }
Esempio n. 7
0
        public void Should_be_possible_to_get_a_value_of_filter_element_in_a_set()
        {
            set    setElement  = SetFactory.GetSetFromDefinitionsOfRegistryObject("definitionsWithSet.xml", "oval:org.mitre.oval:obj:10000");
            string filterValue = setElement.GetFilterValue();

            Assert.AreEqual("oval:org.mitre.oval:ste:99", filterValue);
        }
 public override ISet <Expression> GetGen(BasicBlock block)
 {
     return(SetFactory.GetSet(
                block.Commands
                .OfType <Assignment>()
                .Select(x => x.Value)));
 }
Esempio n. 9
0
        public static ISet <Edge <BasicBlock> > FindReverseEdges(ControlFlowGraph.Graph g)
        {
            ISet <Edge <BasicBlock> > res = SetFactory.GetEdgesSet();//new SortedSet<Edge <BasicBlock>>();

            Dictionary <Edge <BasicBlock>, EdgeType> ClassifiedEdges =
                EdgeClassification.EdgeClassification.ClassifyEdge(g);

            Dictionary <int, int> Dominators =
                ImmediateDominator.FindImmediateDominator(g);

            var RetreatingEdges = ClassifiedEdges.Where(x => x.Value == EdgeType.Retreating);

            foreach (var edg in RetreatingEdges)
            {
                var  edge      = edg.Key;
                int  key       = edge.Source.BlockId;
                int  value     = edge.Target.BlockId;
                bool isReverse = false;
                while (Dominators.ContainsKey(key) && Dominators[key] != key && !isReverse)
                {
                    key       = Dominators[key];
                    isReverse = (key == value);
                }
                if (isReverse)
                {
                    res.Add(edge);
                }
            }

            return(res);
        }
Esempio n. 10
0
        public void Should_be_possible_to_get_an_item_value()
        {
            set    setElement = SetFactory.GetSetFromDefinitionsOfRegistryObject("definitionsWithSet.xml", "oval:org.mitre.oval:obj:5000");
            object itemValue  = setElement.GetItemValue(set_items.set);

            Assert.IsNotNull(itemValue, "item value not found in set element");
        }
        public override ISet <T> TransferFunction(ISet <T> input, BasicBlock block)
        {
            var result = SetFactory.GetSet <T>(input);

            result.ExceptWith(GetKill(block));
            result.UnionWith(GetGen(block));
            return(result);
        }
 public FestivalController(IStage stage)
 {
     this.stage             = stage;
     this.setFactory        = new SetFactory();
     this.instrumentFactory = new InstrumentFactory();
     this.performerFactory  = new PerformerFactory();
     this.songFactory       = new SongFactory();
 }
 public override ISet <CommandNumber> GatherOperation(IEnumerable <ISet <CommandNumber> > blocks)
 {
     return(blocks.Aggregate(SetFactory.GetSet <CommandNumber>(), (res, b) =>
     {
         res.UnionWith(b);
         return res;
     }));
 }
        public override ISet <CommandNumber> CommandTransferFunction(ISet <CommandNumber> input, BasicBlock block, int commandNumber)
        {
            GenKillOneCommand genKill = calculator.CalculateGenAndKill(block, commandNumber); var result = SetFactory.GetSet <CommandNumber>(input);

            result.ExceptWith(genKill.Kill);
            result.UnionWith(genKill.Gen == null ? SetFactory.GetSet <CommandNumber>() : SetFactory.GetSet(genKill.Gen));
            return(result);
        }
Esempio n. 15
0
        public void Should_be_possible_to_verify_if_a_set_has_another_set()
        {
            set setElement = SetFactory.GetSetFromDefinitionsOfRegistryObject("definitionsWithSet.xml", "oval:org.mitre.oval:obj:5000");

            Assert.AreEqual(true, setElement.ExistsAnotherSetElement(), "the set element not has another set");

            setElement = SetFactory.GetSetFromDefinitionsOfRegistryObject("definitionsWithSet.xml", "oval:org.mitre.oval:obj:6000");
            Assert.AreEqual(false, setElement.ExistsAnotherSetElement(), "the set element has another set");
        }
Esempio n. 16
0
        public override ISet <CommandNumber> GatherOperation(IEnumerable <ISet <CommandNumber> > blocks)
        {
            ISet <CommandNumber> res = SetFactory.GetSet <CommandNumber>();

            foreach (var command in blocks)
            {
                res.UnionWith(command);
            }
            return(res);
        }
        public override ISet <Expression> GatherOperation(IEnumerable <ISet <Expression> > blocks)
        {
            ISet <Expression> intersection = SetFactory.GetSet((IEnumerable <Expression>)blocks.First());

            foreach (var block in blocks.Skip(1))
            {
                intersection.IntersectWith(block);
            }

            return(intersection);
        }
        public override ISet <string> GatherOperation(IEnumerable <ISet <string> > blocks)
        {
            ISet <string> union = SetFactory.GetSet((IEnumerable <string>)blocks.First());

            foreach (var block in blocks.Skip(1))
            {
                union.UnionWith(block);
            }

            return(union);
        }
Esempio n. 19
0
 static ChildSafety()
 {
     ChildSafety.factoryDust = new SetFactory(268);
     ChildSafety.factoryGore = new SetFactory(907);
     SetFactory setFactory = ChildSafety.factoryGore;
     int[] numArray = new int[] { 11, 12, 13, 16, 17, 42, 53, 44, 51, 52, 53, 54, 55, 56, 57, 61, 62, 63, 67, 68, 69, 99, 106, 120, 130, 131, 147, 148, 149, 150, 156, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 213, 217, 218, 219, 220, 221, 222, 257, 265, 266, 267, 268, 269, 276, 277, 278, 279, 280, 281, 282, 314, 321, 322, 326, 331, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 375, 376, 377, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 435, 436, 437, 521, 522, 523, 525, 526, 527, 542, 570, 571, 572, 580, 581, 582, 603, 604, 605, 606, 610, 611, 612, 613, 614, 615, 616, 617, 618, 639, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 734, 728, 729, 730, 731, 732, 733, 825, 826, 827, 848, 849, 850, 851, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 892, 893, 898, 899 };
     ChildSafety.SafeGore = setFactory.CreateBoolSet(numArray);
     SetFactory setFactory1 = ChildSafety.factoryDust;
     int[] numArray1 = new int[] { 5, 227 };
     ChildSafety.SafeDust = setFactory1.CreateBoolSet(true, numArray1);
     ChildSafety.Disabled = true;
 }
Esempio n. 20
0
        public static void Main(string[] args)
        {
            IStage              stage              = new Stage();
            ISetFactory         setFactory         = new SetFactory();
            IInstrumentFactory  instrumentFactory  = new InstrumentFactory();
            ISetController      setController      = new SetController(stage);
            IReader             reader             = new ConsoleReader();
            IWriter             writer             = new ConsoleWriter();
            IFestivalController festivalController = new FestivalController(stage, setFactory, setController, instrumentFactory);
            IEngine             engine             = new Engine(reader, writer, festivalController, setController);

            engine.Run();
        }
Esempio n. 21
0
        public void Should_be_possible_to_get_an_object_references_from_a_set()
        {
            set setElement = SetFactory.GetSetFromDefinitionsOfRegistryObject("definitionsWithSet.xml", "oval:org.mitre.oval:obj:7000");
            IEnumerable <string> objectReferences = setElement.GetObjectReferences();

            Assert.AreEqual(2, objectReferences.Count(), "the number of objectReferences is not expected");

            Object firstObject  = objectReferences.Where(obj => obj == "oval:org.mitre.oval:obj:4000").SingleOrDefault();
            Object secondObject = objectReferences.Where(obj => obj == "oval:org.mitre.oval:obj:2000").SingleOrDefault();

            Assert.IsNotNull(firstObject, "the object expected is not found");
            Assert.IsNotNull(secondObject, "the object expected is not found");
        }
Esempio n. 22
0
        static ChildSafety()
        {
            ChildSafety.factoryDust = new SetFactory(268);
            ChildSafety.factoryGore = new SetFactory(907);
            SetFactory setFactory = ChildSafety.factoryGore;

            int[] numArray = new int[] { 11, 12, 13, 16, 17, 42, 53, 44, 51, 52, 53, 54, 55, 56, 57, 61, 62, 63, 67, 68, 69, 99, 106, 120, 130, 131, 147, 148, 149, 150, 156, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 213, 217, 218, 219, 220, 221, 222, 257, 265, 266, 267, 268, 269, 276, 277, 278, 279, 280, 281, 282, 314, 321, 322, 326, 331, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 375, 376, 377, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 435, 436, 437, 521, 522, 523, 525, 526, 527, 542, 570, 571, 572, 580, 581, 582, 603, 604, 605, 606, 610, 611, 612, 613, 614, 615, 616, 617, 618, 639, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 734, 728, 729, 730, 731, 732, 733, 825, 826, 827, 848, 849, 850, 851, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 892, 893, 898, 899 };
            ChildSafety.SafeGore = setFactory.CreateBoolSet(numArray);
            SetFactory setFactory1 = ChildSafety.factoryDust;

            int[] numArray1 = new int[] { 5, 227 };
            ChildSafety.SafeDust = setFactory1.CreateBoolSet(true, numArray1);
            ChildSafety.Disabled = true;
        }
Esempio n. 23
0
        public static bool Create <TKey, TValue>(GrowOnlyHashTable <TKey, GrowOnlySet <TValue> > ht,
                                                 TKey key,
                                                 out GrowOnlySet <TValue> set)
        {
            if (ht.TryGetValue(key, out set) == false)
            {
                set = SetFactory.New <TValue>( );

                ht[key] = set;

                return(false);
            }

            return(true);
        }
Esempio n. 24
0
        //--//

        public static bool CreateWithReferenceEquality <TKey, TValue>(GrowOnlyHashTable <TKey, GrowOnlySet <TValue> > ht,
                                                                      TKey key,
                                                                      out GrowOnlySet <TValue> set) where TValue : class
        {
            if (ht.TryGetValue(key, out set) == false)
            {
                set = SetFactory.NewWithReferenceEquality <TValue>( );

                ht[key] = set;

                return(false);
            }

            return(true);
        }
Esempio n. 25
0
        public override sealed string[] ListAll()
        {
            EnsureOpen();
            // NOTE: fileMap.keySet().toArray(new String[0]) is broken in non Sun JDKs,
            // and the code below is resilient to map changes during the array population.
            //IDictionary<string, RAMFile>.KeyCollection fileNames = FileMap.Keys;
            ISet <string>  fileNames = SetFactory.CreateHashSet(FileMap.Keys);//just want a set of strings
            IList <string> names     = new List <string>(fileNames.Count);

            foreach (string name in fileNames)
            {
                names.Add(name);
            }
            return(names.ToArray());
        }
Esempio n. 26
0
        public static void Main(string[] args)
        {
            IStage              stage              = new Stage();
            IReader             reader             = new ConsoleReader();
            IWriter             writer             = new ConsoleWriter();
            IInstrumentFactory  instrumentFactory  = new InstrumentFactory();
            IPerformerFactory   performerFactory   = new PerformerFactory();
            ISetFactory         setFactory         = new SetFactory();
            ISongFactory        songFactory        = new SongFactory();
            IFestivalController festivalController = new FestivalController(stage, instrumentFactory, performerFactory, setFactory, songFactory);
            ISetController      setController      = new SetController(stage);

            var engine = new Engine(festivalController, setController, reader, writer);

            engine.Run();
        }
 public GenKillOneCommandCalculator(Graph g)
 {
     graph = g;
     CommandStorage = new Dictionary<string, ISet<CommandNumber>>();
     foreach (BasicBlock block in graph)
         for (int i = 0; i < block.Commands.Count(); i++)
         {
             var command = block.Commands[i];
             if (command.GetType() == typeof(Assignment))
                 if (CommandStorage.ContainsKey((command as Assignment).Target.Name))
                     CommandStorage[(command as Assignment).Target.Name].Add(new CommandNumber(block.BlockId, i));
                 else
                     CommandStorage.Add((command as Assignment).Target.Name,
                         SetFactory.GetSet(new CommandNumber(block.BlockId, i)));
         }
     Kill = SetFactory.GetSet<CommandNumber>();
 }
Esempio n. 28
0
        static TransferFunctionStorage <ISet <V> > ApplyAscendingPart <V>(Graph graph, List <Region> regions, SetIterativeAlgorithmParameters <V> param)
        {
            TransferFunctionStorage <ISet <V> > result = new TransferFunctionStorage <ISet <V> >();

            foreach (Region r in regions)
            {
                LeafRegion leaf = r as LeafRegion;
                TransferFunctionStorage <ISet <V> > clone = result.Clone();
                if (leaf != null)
                {
                    //////
                    for (int i = graph.Count(); i < regions.Count; ++i)
                    {
                        result[regions[i], RegionDirection.Out, leaf] = input => param.TransferFunction(input, leaf.Block);
                    }
                    /////
                    result[leaf, RegionDirection.In, leaf]  = Identity;
                    result[leaf, RegionDirection.Out, leaf] = input => param.TransferFunction(input, leaf.Block);
                }
                BodyRegion body = r as BodyRegion;
                if (body != null)
                {
                    foreach (Region s in body.Regions)
                    {
                        LeafRegion header = s as LeafRegion;
                        if (header != null)
                        {
                            result[body, RegionDirection.In, s] = Identity;
                        }
                        else
                        {
                            result[body, RegionDirection.In, s] = input => GatherFunctionsResults(input, clone, body, s.Header.InputBlocks, graph, param);
                        }
                        CalculateForOutputBlocks(result, body, s, s.OutputBlocks, graph);
                    }
                }
                LoopRegion loop = r as LoopRegion;
                if (loop != null)
                {
                    result[loop, RegionDirection.In, loop.Body] = input => SetFactory.GetSet <V>(input.Union(GatherFunctionsResults(input, clone, loop.Body, loop.Header.InputBlocks, graph, param)));
                    CalculateForOutputBlocks(result, loop, loop.Body, loop.OutputBlocks, graph);
                }
            }
            return(result);
        }
Esempio n. 29
0
 public void EnsurePassedFactoriesAreUsed(int value1, int value2, int value3)
 {
     int[] values={value1,value2,value3};
     int i = 0;
     factoryMock.Setup(f => f.Generate()).Returns(() =>
         {
             var value = values[i];
             i++;
             return value;
         });
     var factory = new SetFactory<int>(factoryMock.Object);
     var result = factory.Generate(3);
     i = 0;
     foreach (var value in values)
     {
        Assert.Contains(value,result);
     }
 }
Esempio n. 30
0
        public static void Main()
        {
            IReader reader = new Reader();
            IWriter writer = new Writer();

            ISetFactory        setFactory        = new SetFactory();
            IInstrumentFactory instrumentFactory = new InstrumentFactory();
            IPerformerFactory  performerFactory  = new PerformerFactory();
            ISongFactory       songFactory       = new SongFactory();

            IStage              stage              = new Stage();
            ISetController      setController      = new SetController(stage);
            IFestivalController festivalController =
                new FestivalController(stage, setFactory, instrumentFactory, performerFactory, songFactory);

            IEngine engine = new Engine(reader, writer, setController, festivalController);

            engine.Run();
        }
Esempio n. 31
0
        public override ISet <CommandNumber> GetGen(BasicBlock block)
        {
            List <GenKillOneCommand> listGenKill = block.Commands.Select((x, i) => commandCalc.CalculateGenAndKill(block, i)).ToList();

            ISet <CommandNumber> genB  = SetFactory.GetSet <CommandNumber>();
            ISet <CommandNumber> killS = SetFactory.GetSet <CommandNumber>();

            for (int i = block.Commands.Count - 1; i >= 0; i--)
            {
                ISet <CommandNumber> genS = SetFactory.GetSet <CommandNumber>();
                if (listGenKill[i].Gen != null)
                {
                    genS.Add(listGenKill[i].Gen);
                }
                genS.ExceptWith(killS);
                genB.UnionWith(genS);

                killS.UnionWith(listGenKill[i].Kill);
            }

            return(genB);
        }
Esempio n. 32
0
        public static void Main(string[] args)
        {
            IList <ISet>       sets       = new List <ISet>();
            IList <ISong>      songs      = new List <ISong>();
            IList <IPerformer> performers = new List <IPerformer>();

            Stage stage = new Stage(sets, songs, performers);

            IReader            reader            = new ConsoleReader();
            IWriter            writer            = new ConsoleWriter();
            ISetFactory        setFactory        = new SetFactory();
            IInstrumentFactory instrumentFactory = new InstrumentFactory();
            IPerformerFactory  performerFactory  = new PerformerFactory();
            ISongFactory       songFactory       = new SongFactory();

            IFestivalController festivalController = new FestivalController(stage, setFactory, instrumentFactory, performerFactory, songFactory);
            ISetController      setController      = new SetController(stage);

            var engine = new Engine(reader, writer, festivalController, setController);

            engine.Run();
        }