Exemple #1
0
        public FactUniverse()
        {
            _knownTypes = new ObservableCache <Type, TypeFacts>(
                ReflectionHelper.TypeEqualityComparer, CreateTypeFacts);
            _knownMethods = new ObservableCache <MethodBase, MethodFacts>(
                ReflectionHelper.MethodEqualityComparer, CreateMethodFacts);
            _knownFields = new ObservableCache <FieldInfo, FieldFacts>(
                ReflectionHelper.FieldEqualityComparer, CreateFieldFacts);

            KnownTypes       = _knownTypes;
            KnownMethodBases = _knownMethods;

            _knownTypes.AutoDo(OnNewType);
            KnownInterfaces = KnownTypes
                              .Where(type => type.TheType.IsInterface);

            KnownAbstractClasses = KnownTypes
                                   .Where(type => type.TheType.IsAbstract);

            KnownValueTypes = KnownTypes
                              .Where(type => type.TheType.IsValueType);

            KnownInstantiables = KnownTypes
                                 .Where(type => !type.TheType.IsInterface && !type.TheType.IsAbstract && !type.TheType.IsGenericParameter);

            KnownMethods = KnownMethodBases
                           .Where(method => method.Method is MethodInfo);
            KnownConstructors = KnownMethodBases
                                .Where(method => method.Method is ConstructorInfo);

            KnownMethodBases.ObserveOn(Scheduler.CurrentThread).AutoDo(OnNewMethod);

            KnownAllocationSites = _allocSites.AsObservable();
        }
Exemple #2
0
        public void CreateHTMLReport(string path)
        {
            HTMLReport rep = new HTMLReport(path);

            rep.BeginDocument("Fact universe");

            rep.AddSection(1, "Types");
            rep.BeginTable(1, "Name", "Realizations", "Mutable");
            KnownTypes
            .ToEnumerable()
            .OrderBy(t => t.TheType.FullName)
            .ToObservable()
            .AutoDo(t =>
                    rep.AddRow(t.TheType.FullName,
                               string.Join(", ", RealizationsOf(t.TheType).ToEnumerable().Select(tr => tr.FullName)),
                               t.IsMutable ? "yes" : "no"));
            rep.EndTable();

            rep.AddSection(1, "Methods");
            KnownMethodBases
            .ToEnumerable()
            .OrderBy(m => m.Method.Name)
            .ToObservable()
            .AutoDo(mf =>
            {
                rep.AddSection(2, mf.Method.ToString());
                rep.AddText("Declaring type: " + mf.Method.DeclaringType.FullName);
                rep.AddSection(3, "Callees:");
                rep.AddText(string.Join(", ", mf.CalledMethods.Select(cm => cm.ToString())));
                rep.AddSection(3, "Callers:");
                rep.AddText(string.Join(", ", mf.CallingMethods.Select(cm => cm.ToString())));
                if (mf.Method.GetParameters().Length > 0)
                {
                    rep.AddSection(3, "Argument candidates:");
                    rep.BeginBulletList();
                    foreach (ParameterInfo pi in mf.Method.GetParameters())
                    {
                        rep.BeginListItem();
                        rep.AddText(pi.Name + ": ");
                        var acs = mf.GetArgumentCandidates(pi);
                        if (acs.Any())
                        {
                            rep.BeginBulletList();
                            foreach (ElementSource src in acs)
                            {
                                rep.AddListItem(src.ToString());
                            }
                            rep.EndBulletList();
                        }
                        rep.EndListItem();
                    }
                    rep.EndBulletList();
                }
                if (mf.Mutations.Any())
                {
                    rep.AddSection(3, "Mutations:");
                    rep.BeginBulletList();
                    foreach (ElementMutation mut in mf.Mutations)
                    {
                        rep.BeginListItem();
                        if (mut is StoreFieldMutation)
                        {
                            rep.AddText("store field");
                        }
                        else if (mut is WriteArrayMutation)
                        {
                            rep.AddText("write array");
                        }
                        else if (mut is IndirectMutation)
                        {
                            rep.AddText("indirect store");
                        }
                        else
                        {
                            rep.AddText("???");
                        }

                        rep.BeginBulletList();
                        rep.AddListItem("Mutatee: " + mut.Mutatee);

                        var mt = mut.GetMutatedTerminals();
                        if (mt.Any())
                        {
                            rep.AddListItem("Mutated terminals:");
                            rep.BeginBulletList();
                            foreach (ElementSource src in mt)
                            {
                                rep.AddListItem(src.ToString());
                            }
                            rep.EndBulletList();
                        }

                        var st = mut.GetSubMutatedTerminals();
                        if (st.Any())
                        {
                            rep.AddListItem("Sub-mutated terminals:");
                            rep.BeginBulletList();
                            foreach (ElementSource src in st)
                            {
                                rep.AddListItem(src.ToString());
                            }
                            rep.EndBulletList();
                        }

                        rep.EndBulletList();
                        rep.EndListItem();
                    }
                    rep.EndBulletList();
                }
            });

            rep.EndDocument();
            rep.Close();
        }