Пример #1
0
 public void BranchConditionalAccessDefiniteAssignment()
 {
     if (conditional_access == null)
     {
         conditional_access = BranchDefiniteAssignment();
     }
 }
Пример #2
0
		public DefiniteAssignmentBitSet BranchDefiniteAssignment ()
		{
			var dat = DefiniteAssignment;
			if (dat != DefiniteAssignmentBitSet.Empty)
				DefiniteAssignment = new DefiniteAssignmentBitSet (dat);
			return dat;
		}
Пример #3
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);
        }
Пример #4
0
        public DefiniteAssignmentBitSet BranchDefiniteAssignment(DefiniteAssignmentBitSet da)
        {
            if (da != DefiniteAssignmentBitSet.Empty)
            {
                DefiniteAssignment = new DefiniteAssignmentBitSet(da);
            }

            return(da);
        }
Пример #5
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);
        }
Пример #6
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]);
        }
Пример #7
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;
     }
 }
Пример #8
0
        public void SetAssigned(DefiniteAssignmentBitSet vector, bool generatedAssignment)
        {
            if (Length == 1)
            {
                vector.Set(Offset);
            }
            else
            {
                vector.Set(Offset, Length);
            }

            if (!generatedAssignment)
            {
                IsEverAssigned = true;
            }
        }
Пример #9
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);
        }
Пример #10
0
        private 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);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
0
        public static bool IsIncluded(DefiniteAssignmentBitSet set, DefiniteAssignmentBitSet test)
        {
            var set_bits = set.large_bits;

            if (set_bits == null)
            {
                return((set.bits & test.bits & ~copy_on_write_flag) == (set.bits & ~copy_on_write_flag));
            }

            var test_bits = test.large_bits;

            for (int i = 0; i < set_bits.Length; ++i)
            {
                if ((set_bits[i] & test_bits[i]) != set_bits[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #14
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;
		}
Пример #15
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;
		}
Пример #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;
			}
		}
Пример #17
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);
		}
Пример #18
0
		public void SetAssigned (DefiniteAssignmentBitSet vector, bool generatedAssignment)
		{
			if (Length == 1)
				vector.Set (Offset);
			else
				vector.Set (Offset, Length);

			if (!generatedAssignment)
				IsEverAssigned = true;
		}
Пример #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];
		}
Пример #20
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;
		}
Пример #21
0
		public DefiniteAssignmentBitSet (DefiniteAssignmentBitSet source)
		{
			large_bits = source.large_bits;
			bits = source.bits | copy_on_write_flag;
		}
Пример #22
0
		public void ConditionalAccessEnd ()
		{
			Debug.Assert (conditional_access != null);
			DefiniteAssignment = conditional_access;
			conditional_access = null;
		}
Пример #23
0
		public DefiniteAssignmentBitSet BranchDefiniteAssignment (DefiniteAssignmentBitSet da)
		{
			if (da != DefiniteAssignmentBitSet.Empty) {
				DefiniteAssignment = new DefiniteAssignmentBitSet (da);
			}

			return da;
		}
Пример #24
0
		public void BranchConditionalAccessDefiniteAssignment ()
		{
			if (conditional_access == null)
				conditional_access = BranchDefiniteAssignment ();
		}
Пример #25
0
 public void SetVariableAssigned(VariableInfo variable, DefiniteAssignmentBitSet da)
 {
     variable.SetAssigned(da, false);
 }
Пример #26
0
 public void ConditionalAccessEnd()
 {
     Debug.Assert(conditional_access != null);
     DefiniteAssignment = conditional_access;
     conditional_access = null;
 }
Пример #27
0
		public DefiniteAssignmentBitSet BranchDefiniteAssignment ()
		{
			var dat = DefiniteAssignment;
			DefiniteAssignment = new DefiniteAssignmentBitSet (dat);
			return dat;
		}
Пример #28
0
		public DefiniteAssignmentBitSet (DefiniteAssignmentBitSet source)
		{
			bits = source.bits;

			copy_on_write = true;
		}
Пример #29
0
		public static bool IsIncluded (DefiniteAssignmentBitSet set, DefiniteAssignmentBitSet test)
		{
			var set_bits = set.large_bits;
			if (set_bits == null)
				return (set.bits & test.bits & ~copy_on_write_flag) == (set.bits & ~copy_on_write_flag);

			var test_bits = test.large_bits;
			for (int i = 0; i < set_bits.Length; ++i) {
				if ((set_bits[i] & test_bits[i]) != set_bits[i])
					return false;
			}

			return true;
		}
Пример #30
0
		public DefiniteAssignmentBitSet BranchDefiniteAssignment ()
		{
			var dat = DefiniteAssignment;
			if (dat != DefiniteAssignmentBitSet.Empty)
				DefiniteAssignment = new DefiniteAssignmentBitSet (dat);
			return dat;
		}
Пример #31
0
		public FlowAnalysisContext (CompilerContext ctx, ParametersBlock parametersBlock)
		{
			this.ctx = ctx;
			this.ParametersBlock = parametersBlock;

			DefiniteAssignment = new DefiniteAssignmentBitSet ();
		}