public override void Accept(Transformer t)
        {
            // TODO This assert breaks when using /internal in System.Data. 
            //A temporaty solution is to avoid outputting something like "Source code printing failed."
            Util.Assert(t.Namespace != null);

            ICollection<Assembly> assemblies = t.Assemblies;

            if (!declaringTypes.Contains(t.Namespace))
            {
                declaringTypes.Add(t.Namespace);
            }

            foreach (Assembly assembly in assemblies)
            {
                string res = null;
                cachedLocations.TryGetValue(assembly, out res);
                if (res == null)
                {   
                    string r = assembly.Location;
                    if (!assemblyNames.Contains(r))
                    {
                        assemblyNames.Add(r);
                        cachedLocations.Add(assembly, r);
                    }
                }
                else
                {
                    assemblyNames.Add(res);
                }
            }
        }
        public override void Accept(Transformer t)
        {
            // TODO This assert breaks when using /internal in System.Data.
            Util.Assert(t.Namespace != null);

            ICollection<Assembly> assemblies = t.Assemblies;

            if (!declaringTypes.Contains(t.Namespace))
            {
                declaringTypes.Add(t.Namespace);
            }

            foreach (Assembly assembly in assemblies)
            {
                string res = null;
                cachedLocations.TryGetValue(assembly, out res);
                if (res == null)
                {   
                    string r = assembly.Location;
                    if (!assemblyNames.Contains(r))
                    {
                        assemblyNames.Add(r);
                        cachedLocations.Add(assembly, r);
                    }
                }
                else
                {
                    assemblyNames.Add(res);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates a Plan.
        /// </summary>
        /// <param name="transfomer">The state transformer that this plan represents.</param>
        /// <param name="parentPlans">The parent plans for this plan.</param>
        /// <param name="parameterChoosers">The parameter choosers for the parent plans.</param>
        /// <param name="resultTypes">The types (and number of) results that executing this plan yields.</param>
        public Plan(Transformer transfomer, Plan[] parentPlans, ParameterChooser[] parameterChoosers)
        {

            this.uniqueId = uniqueIdCounter++;
            this.transformer = transfomer;
            this.parentPlans = parentPlans;

            this.parameterChoosers = parameterChoosers;
            this.activeTupleElements = transformer.DefaultActiveTupleTypes;

            this.resultElementProperties = new ResultElementExecutionProperties[this.activeTupleElements.Length];
            for (int i = 0; i < this.resultElementProperties.Length; i++)
                this.resultElementProperties[i] = new ResultElementExecutionProperties();

            this.treenodes = 1;
            foreach (Plan p in parentPlans)
                this.treenodes += p.treenodes;
        }
 public virtual void Accept(Transformer t)
 {
     // Empty body.
 }
Exemple #5
0
        /// <summary>
        /// Initializes the data structures for Active members, types, and the dependency of methods on types
        /// </summary>
        /// <param name="planManager"></param>
        ///
        ///
        private void InitializeActiveMemberAndDependency(PlanManager planManager)
        {
            //reset all the maps
            activeMembers.Clear();
            activeTypes.Clear();
            typesWithObjects.Clear();
            member2pendingTypes.Clear();
            type2pendingMembers.Clear();


            //get the set of types for which the builderPlans can create an object
            Dictionary <Plan, bool> .KeyCollection plans = planManager.builderPlans.planSet.Keys;
            //we simply look at the return type of the last method of each builder plan. This is sufficient
            //because any intermediate method in a plan will appear as the last method of some prefix plan
            //in the builder plan database
            foreach (Plan plan in plans)
            {
                Transformer tr = plan.transformer;
                Type        t;


                if (tr is MethodCall)
                {
                    t = (tr as MethodCall).method.ReturnType;
                    typesWithObjects[t] = true;
                    RandoopPrintFairStats("InitializeActiveMemberDependency", "[Method]" + t.ToString() + " class is ACTIVE");
                }
                else if (tr is ConstructorCallTransformer)
                {
                    t = (tr as ConstructorCallTransformer).constructor.DeclaringType;
                    typesWithObjects[t] = true;
                    RandoopPrintFairStats("InitializeActiveMemberDependency", "[Constructor]" + t.ToString() + " class is ACTIVE");
                }
                else if (tr is PrimitiveValueTransformer) //for primitive values and string
                {
                    t = (tr as PrimitiveValueTransformer).ftype;
                    typesWithObjects[t] = true;
                    RandoopPrintFairStats("InitializeActiveMemberDependency", "[Constant]" + t.ToString() + " class is ACTIVE");
                }
                else
                {
                    //TODO: ignoring field setters and Array constructors
                }
            }

            //we are only going to try to activate the non-filtered types/methods only
            foreach (ConstructorInfo ci in actions.GetConstructors())
            {
                bool            activeMember = true;
                ParameterInfo[] args         = ci.GetParameters();
                //check if all the arguments can be provided an object
                for (int i = 0; i < args.Length; ++i)
                {
                    ParameterInfo pi = args[i];
                    if (!typesWithObjects.ContainsKey(pi.ParameterType))
                    {
                        RandoopPrintFairStats("InitializeActiveMemberAndDependency", "Can't find argument of type" + pi.ParameterType + "for constructor <" + ci.ToString() + ">");
                        activeMember = false;

                        //compute the dependency of method --> pending types
                        List <Type> output;
                        member2pendingTypes.TryGetValue(ci, out output);
                        if (output == null)
                        {
                            List <Type> l = new List <Type>();
                            l.Add(pi.ParameterType);
                            member2pendingTypes[ci] = l;
                        }
                        else if (!output.Contains(pi.ParameterType))
                        {
                            member2pendingTypes[ci].Add(pi.ParameterType);
                        }


                        //compute the dependency of type --> methods
                        List <MemberInfo> members;
                        type2pendingMembers.TryGetValue(pi.ParameterType, out members);
                        if (members == null)
                        {
                            List <MemberInfo> l = new List <MemberInfo>();
                            l.Add(ci);
                            type2pendingMembers[pi.ParameterType] = l;
                        }
                        else if (!members.Contains(ci))
                        {
                            type2pendingMembers[pi.ParameterType].Add(ci);
                        }
                    }
                }

                if (activeMember) // add it to the active member set and update active types
                {
                    Type ti = ci.DeclaringType;

                    List <MemberInfo> memberList;
                    activeMembers.TryGetValue(ti, out memberList);
                    if (memberList == null)
                    {
                        memberList = new List <MemberInfo>();
                        memberList.Add(ci);
                        activeMembers[ti] = memberList;
                    }
                    else
                    {
                        //there can't be any repeats
                        activeMembers[ti].Add(ci);
                    }

                    //activate the type
                    activeTypes[ti] = true;
                    RandoopPrintFairStats("InitializeActiveMemberAndDependency", "Adding <ActiveType, ActiveMember>: <" + ti.ToString() + "," + ci.ToString() + ">");
                }
            }

            foreach (MethodInfo mi in actions.GetMethods())
            {
                bool activeMember = true;

                //receiver is treated separately
                if (!typesWithObjects.ContainsKey(mi.DeclaringType))
                {
                    Type ti = mi.DeclaringType;

                    RandoopPrintFairStats("InitializeActiveMemberAndDependency", "Can't find argument of type" + ti + "for method <" + mi.ToString() + ">");

                    activeMember = false;

                    //compute the dependency of method --> pending types
                    List <Type> output;
                    member2pendingTypes.TryGetValue(mi, out output);
                    if (output == null)
                    {
                        List <Type> l = new List <Type>();
                        l.Add(ti);
                        member2pendingTypes[mi] = l;
                    }
                    else if (!output.Contains(ti))
                    {
                        member2pendingTypes[mi].Add(ti);
                    }


                    //compute the dependency of type --> methods
                    List <MemberInfo> memberList;
                    type2pendingMembers.TryGetValue(ti, out memberList);
                    if (memberList == null)
                    {
                        List <MemberInfo> l = new List <MemberInfo>();
                        l.Add(mi);
                        type2pendingMembers[ti] = l;
                    }
                    else if (!memberList.Contains(mi))
                    {
                        type2pendingMembers[ti].Add(mi);
                    }
                }

                //check if all the arguments can be provided an object
                ParameterInfo[] args = mi.GetParameters();
                for (int i = 0; i < args.Length; ++i)
                {
                    ParameterInfo pi = args[i];
                    if (!typesWithObjects.ContainsKey(pi.ParameterType))
                    {
                        RandoopPrintFairStats("InitializeActiveMemberAndDependency", "Can't find argument of type" + pi.ParameterType + "for method <" + mi.ToString() + ">");
                        activeMember = false;

                        //compute the dependency of method --> pending types
                        List <Type> output;
                        member2pendingTypes.TryGetValue(mi, out output);
                        if (output == null)
                        {
                            List <Type> l = new List <Type>();
                            l.Add(pi.ParameterType);
                            member2pendingTypes[mi] = l;
                        }
                        else if (!output.Contains(pi.ParameterType))
                        {
                            member2pendingTypes[mi].Add(pi.ParameterType);
                        }


                        //compute the dependency of type --> methods
                        List <MemberInfo> members;
                        type2pendingMembers.TryGetValue(pi.ParameterType, out members);
                        if (members == null)
                        {
                            List <MemberInfo> l = new List <MemberInfo>();
                            l.Add(mi);
                            type2pendingMembers[pi.ParameterType] = l;
                        }
                        else if (!members.Contains(mi))
                        {
                            type2pendingMembers[pi.ParameterType].Add(mi);
                        }
                    }
                }

                if (activeMember)
                {
                    Type ti = mi.DeclaringType;

                    List <MemberInfo> memberList;
                    activeMembers.TryGetValue(ti, out memberList);
                    if (memberList == null)
                    {
                        memberList = new List <MemberInfo>();
                        memberList.Add(mi);
                        activeMembers[ti] = memberList;
                    }
                    else
                    {
                        //there can't be any repeats
                        activeMembers[ti].Add(mi);
                    }

                    //activate the type
                    activeTypes[ti] = true;
                    RandoopPrintFairStats("InitializeActiveMemberAndDependency", "Adding <ActiveType, ActiveMember>: <" + ti.ToString() + "," + mi.ToString() + ">");
                }
            }
        }
Exemple #6
0
 public virtual void Accept(Transformer t)
 {
     // Empty body.
 }