コード例 #1
0
        /// <summary>
        /// Adds a new type expression.
        /// </summary>
        /// <param name="type">WriteType expression to add.</param>
        /// <returns>If the type has been added</returns>
        public bool AddType(TypeExpression type)
        {
            bool             added        = true;
            IntersectionType intersection = TypeExpression.As <IntersectionType>(type);

            if (intersection != null)
            {
                foreach (TypeExpression t in intersection.typeSet)
                {
                    added = added && this.AddType(t);
                }
                this.ValidTypeExpression = false;
                return(added);
            }
            Predicate <TypeExpression> predicate = delegate(TypeExpression te2) {
                return((bool)te2.AcceptOperation(new EquivalentOperation(type), null));
            };

            if (this.typeSet.Find(predicate) == null)
            {
                this.typeSet.Add(type);
                this.ValidTypeExpression = false;
                return(true);
            }
            return(false);
        }
コード例 #2
0
        // SSA

        #region Clone()
        /// <summary>
        /// Clones a type to be used in SSA. It must taken into account that:
        /// - In case it has no type variables, no clone is performed
        /// - WriteType variables, equivalence classes and substitutions are cloned
        /// </summary>
        /// <param name="clonedTypeVariables">WriteType variables that have been cloned.</param>
        /// <param name="equivalenceClasses">Equivalence classes of the type cloned variables. These
        /// equivalence classes need to be updated with the new cloned type variables.</param>
        /// <param name="methodAnalyzed">The method that is being analyzed when the operation is performed.</param>
        /// <returns>The cloned type</returns>
        internal override TypeExpression Clone(IDictionary <int, TypeVariable> clonedTypeVariables, IList <EquivalenceClass> equivalenceClasses, MethodType methodAnalyzed)
        {
            if (!this.HasTypeVariables())
            {
                return(this);
            }
            IntersectionType newIntersectionType = (IntersectionType)this.MemberwiseClone();

            newIntersectionType.typeSet = new List <TypeExpression>();
            // * Clones all the types in the union
            foreach (TypeExpression type in this.typeSet)
            {
                newIntersectionType.typeSet.Add(type.Clone(clonedTypeVariables, equivalenceClasses, methodAnalyzed));
            }
            return(newIntersectionType);
        }
コード例 #3
0
        /// <summary>
        /// Method that clones each type variable of a type expression.
        /// Equivalence classes are not cloned (but included in the equivalenceClasses parameter.
        /// The default implementation is do nothing (for built-in types).
        /// </summary>
        /// <param name="typeVariableMappings">Each new type varaiable represent a copy of another existing one.
        /// This parameter is a mapping between them, wher tmpName=old and value=new</param>
        /// <param name="equivalenceClasses">Each equivalence class of all the type variables.</param>
        /// <param name="clonedClasses">This parameter collects the set of all cloned classes. It is used to detect infinite recursion.</param>
        /// <returns>The new type expression (itself by default)</returns>
        public override TypeExpression CloneTypeVariables(IDictionary <TypeVariable, TypeVariable> typeVariableMappings, IList <EquivalenceClass> equivalenceClasses, IList <ClassType> clonedClasses)
        {
            if (!this.HasTypeVariables())
            {
                return(this);
            }
            IntersectionType       newType    = (IntersectionType)this.MemberwiseClone();
            IList <TypeExpression> oldTypeSet = this.typeSet;

            newType.typeSet = new List <TypeExpression>();
            foreach (TypeExpression oldType in oldTypeSet)
            {
                newType.typeSet.Add(oldType.CloneTypeVariables(typeVariableMappings, equivalenceClasses, clonedClasses));
            }
            newType.ValidTypeExpression = false;
            return(newType);
        }