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

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

            if (!generatedAssignment)
            {
                IsEverAssigned = true;
            }
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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;
		}
Exemple #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;
		}
Exemple #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;
			}
		}
Exemple #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);
		}
Exemple #18
0
		public void SetAssigned (DefiniteAssignmentBitSet vector, bool generatedAssignment)
		{
			if (Length == 1)
				vector.Set (Offset);
			else
				vector.Set (Offset, Length);

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

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

			copy_on_write = true;
		}
Exemple #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;
		}
Exemple #30
0
		public DefiniteAssignmentBitSet BranchDefiniteAssignment ()
		{
			var dat = DefiniteAssignment;
			if (dat != DefiniteAssignmentBitSet.Empty)
				DefiniteAssignment = new DefiniteAssignmentBitSet (dat);
			return dat;
		}
Exemple #31
0
		public FlowAnalysisContext (CompilerContext ctx, ParametersBlock parametersBlock)
		{
			this.ctx = ctx;
			this.ParametersBlock = parametersBlock;

			DefiniteAssignment = new DefiniteAssignmentBitSet ();
		}