Example #1
0
 public void BranchConditionalAccessDefiniteAssignment()
 {
     if (conditional_access == null)
     {
         conditional_access = BranchDefiniteAssignment();
     }
 }
Example #2
0
        public static DefiniteAssignmentBitSet operator |(DefiniteAssignmentBitSet a, DefiniteAssignmentBitSet b)
        {
            if (AreEqual(a, b))
            {
                return(a);
            }

            DefiniteAssignmentBitSet res;

            if (a.large_bits == null)
            {
                res       = new DefiniteAssignmentBitSet(a);
                res.bits |= b.bits;
                res.bits &= ~copy_on_write_flag;
                return(res);
            }

            res = new DefiniteAssignmentBitSet(a);
            res.Clone();
            var dest = res.large_bits;
            var src  = b.large_bits;

            for (int i = 0; i < dest.Length; ++i)
            {
                dest[i] |= src[i];
            }

            return(res);
        }
Example #3
0
        public DefiniteAssignmentBitSet BranchDefiniteAssignment(DefiniteAssignmentBitSet da)
        {
            if (da != DefiniteAssignmentBitSet.Empty)
            {
                DefiniteAssignment = new DefiniteAssignmentBitSet(da);
            }

            return(da);
        }
Example #4
0
        public bool IsAssigned(DefiniteAssignmentBitSet vector)
        {
            if (vector == null)
            {
                return(true);
            }

            if (vector [Offset])
            {
                return(true);
            }

            // Unless this is a struct
            if (!TypeInfo.IsStruct)
            {
                return(false);
            }

            //
            // Following case cannot be handled fully by SetStructFieldAssigned
            // because we may encounter following case
            //
            // struct A { B b }
            // struct B { int value; }
            //
            // setting a.b.value is propagated only to B's vector and not upwards to possible parents
            //
            //
            // Each field must be assigned
            //
            for (int i = Offset + 1; i <= TypeInfo.Length + Offset; i++)
            {
                if (!vector[i])
                {
                    return(false);
                }
            }

            // Ok, now check all fields which are structs.
            for (int i = 0; i < sub_info.Length; i++)
            {
                VariableInfo sinfo = sub_info[i];
                if (sinfo == null)
                {
                    continue;
                }

                if (!sinfo.IsAssigned(vector))
                {
                    return(false);
                }
            }

            vector.Set(Offset);
            return(true);
        }
Example #5
0
        public bool IsStructFieldAssigned(DefiniteAssignmentBitSet vector, string field_name)
        {
            int field_idx = TypeInfo.GetFieldIndex(field_name);

            if (field_idx == 0)
            {
                return(true);
            }

            return(vector [Offset + field_idx]);
        }
Example #6
0
 public DefiniteAssignmentBitSet(DefiniteAssignmentBitSet source)
 {
     if (source.large_bits != null)
     {
         large_bits = source.large_bits;
         bits       = source.bits | copy_on_write_flag;
     }
     else
     {
         bits = source.bits & ~copy_on_write_flag;
     }
 }
Example #7
0
        public static DefiniteAssignmentBitSet And(List <DefiniteAssignmentBitSet> das)
        {
            if (das.Count == 0)
            {
                throw new ArgumentException("Empty das");
            }

            DefiniteAssignmentBitSet res = das[0];

            for (int i = 1; i < das.Count; ++i)
            {
                res &= das[i];
            }

            return(res);
        }
Example #8
0
        public void SetAssigned(DefiniteAssignmentBitSet vector, bool generatedAssignment)
        {
            if (Length == 1)
            {
                vector.Set(Offset);
            }
            else
            {
                vector.Set(Offset, Length);
            }

            if (!generatedAssignment)
            {
                IsEverAssigned = true;
            }
        }
Example #9
0
        public static bool AreEqual(DefiniteAssignmentBitSet a, DefiniteAssignmentBitSet b)
        {
            if (a.large_bits == null)
            {
                return((a.bits & ~copy_on_write_flag) == (b.bits & ~copy_on_write_flag));
            }

            for (int i = 0; i < a.large_bits.Length; ++i)
            {
                if (a.large_bits[i] != b.large_bits[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Example #10
0
        public void SetStructFieldAssigned(DefiniteAssignmentBitSet vector, string field_name)
        {
            if (vector [Offset])
            {
                return;
            }

            int field_idx = TypeInfo.GetFieldIndex(field_name);

            if (field_idx == 0)
            {
                return;
            }

            var complex_field = TypeInfo.GetStructField(field_name);

            if (complex_field != null)
            {
                vector.Set(Offset + complex_field.Offset, complex_field.TotalLength);
            }
            else
            {
                vector.Set(Offset + field_idx);
            }

            IsEverAssigned = true;

            //
            // Each field must be assigned before setting master bit
            //
            for (int i = Offset + 1; i < TypeInfo.TotalLength + Offset; i++)
            {
                if (!vector[i])
                {
                    return;
                }
            }

            //
            // Set master struct flag to assigned when all tested struct
            // fields have been assigned
            //
            vector.Set(Offset);
        }
Example #11
0
        public bool AddReachedLabel(Statement label)
        {
            List <DefiniteAssignmentBitSet> das;

            if (LabelStack == null)
            {
                LabelStack = new Dictionary <Statement, List <DefiniteAssignmentBitSet> > ();
                das        = null;
            }
            else
            {
                LabelStack.TryGetValue(label, out das);
            }

            if (das == null)
            {
                das = new List <DefiniteAssignmentBitSet> ();
                das.Add(new DefiniteAssignmentBitSet(DefiniteAssignment));
                LabelStack.Add(label, das);
                return(false);
            }

            foreach (var existing in das)
            {
                if (DefiniteAssignmentBitSet.AreEqual(existing, DefiniteAssignment))
                {
                    return(true);
                }
            }

            if (DefiniteAssignment == DefiniteAssignmentBitSet.Empty)
            {
                das.Add(DefiniteAssignment);
            }
            else
            {
                das.Add(new DefiniteAssignmentBitSet(DefiniteAssignment));
            }

            return(false);
        }
Example #12
0
		public DefiniteAssignmentBitSet BranchDefiniteAssignment (DefiniteAssignmentBitSet da)
		{
			if (da != DefiniteAssignmentBitSet.Empty) {
				DefiniteAssignment = new DefiniteAssignmentBitSet (da);
			}

			return da;
		}
Example #13
0
 public void ConditionalAccessEnd()
 {
     Debug.Assert(conditional_access != null);
     DefiniteAssignment = conditional_access;
     conditional_access = null;
 }
Example #14
0
		public void SetAssigned (DefiniteAssignmentBitSet vector, bool generatedAssignment)
		{
			if (Length == 1)
				vector.Set (Offset);
			else
				vector.Set (Offset, Length);

			if (!generatedAssignment)
				IsEverAssigned = true;
		}
Example #15
0
		public void SetStructFieldAssigned (DefiniteAssignmentBitSet vector, string field_name)
		{
			if (vector [Offset])
				return;

			int field_idx = TypeInfo.GetFieldIndex (field_name);

			if (field_idx == 0)
				return;

			var complex_field = TypeInfo.GetStructField (field_name);
			if (complex_field != null) {
				vector.Set (Offset + complex_field.Offset, complex_field.TotalLength);
			} else {
				vector.Set (Offset + field_idx);
			}

			IsEverAssigned = true;

			//
			// Each field must be assigned before setting master bit
			//
			for (int i = Offset + 1; i < TypeInfo.TotalLength + Offset; i++) {
				if (!vector[i])
					return;
			}

			//
			// Set master struct flag to assigned when all tested struct
			// fields have been assigned
			//
			vector.Set (Offset);
		}
Example #16
0
		public DefiniteAssignmentBitSet (DefiniteAssignmentBitSet source)
		{
			if (source.large_bits != null) {
				large_bits = source.large_bits;
				bits = source.bits | copy_on_write_flag;
			} else {
				bits = source.bits & ~copy_on_write_flag;
			}
		}
Example #17
0
		public static DefiniteAssignmentBitSet operator | (DefiniteAssignmentBitSet a, DefiniteAssignmentBitSet b)
		{
			if (AreEqual (a, b))
				return a;

			DefiniteAssignmentBitSet res;
			if (a.large_bits == null) {
				res = new DefiniteAssignmentBitSet (a);
				res.bits |= b.bits;
				res.bits &= ~copy_on_write_flag;
				return res;
			}

			res = new DefiniteAssignmentBitSet (a);
			res.Clone ();
			var dest = res.large_bits;
			var src = b.large_bits;

			for (int i = 0; i < dest.Length; ++i) {
				dest[i] |= src[i];
			}

			return res;
		}
Example #18
0
		public static bool AreEqual (DefiniteAssignmentBitSet a, DefiniteAssignmentBitSet b)
		{
			if (a.large_bits == null)
				return (a.bits & ~copy_on_write_flag) == (b.bits & ~copy_on_write_flag);

			for (int i = 0; i < a.large_bits.Length; ++i) {
				if (a.large_bits[i] != b.large_bits[i])
					return false;
			}

			return true;
		}
Example #19
0
		public bool IsStructFieldAssigned (DefiniteAssignmentBitSet vector, string field_name)
		{
			int field_idx = TypeInfo.GetFieldIndex (field_name);

			if (field_idx == 0)
				return true;

			return vector [Offset + field_idx];
		}
Example #20
0
		public void BranchConditionalAccessDefiniteAssignment ()
		{
			if (conditional_access == null)
				conditional_access = BranchDefiniteAssignment ();
		}
Example #21
0
		public void ConditionalAccessEnd ()
		{
			Debug.Assert (conditional_access != null);
			DefiniteAssignment = conditional_access;
			conditional_access = null;
		}
Example #22
0
		public bool IsAssigned (DefiniteAssignmentBitSet vector)
		{
			if (vector == null)
				return true;

			if (vector [Offset])
				return true;

			// Unless this is a struct
			if (!TypeInfo.IsStruct)
				return false;

			//
			// Following case cannot be handled fully by SetStructFieldAssigned
			// because we may encounter following case
			// 
			// struct A { B b }
			// struct B { int value; }
			//
			// setting a.b.value is propagated only to B's vector and not upwards to possible parents
			//
			//
			// Each field must be assigned
			//
			for (int i = Offset + 1; i <= TypeInfo.Length + Offset; i++) {
				if (!vector[i])
					return false;
			}

			// Ok, now check all fields which are structs.
			for (int i = 0; i < sub_info.Length; i++) {
				VariableInfo sinfo = sub_info[i];
				if (sinfo == null)
					continue;

				if (!sinfo.IsAssigned (vector))
					return false;
			}
			
			vector.Set (Offset);
			return true;
		}