Exemplo n.º 1
0
        public static bool IsDeclaredWriteConfined(Parameter p)
        {
            if (WorstCase)
            {
                return(false);
            }
            if (PointsToAndEffectsAnnotations.writeConfinedByDefault)
            {
                return(true);
            }
            bool          res  = false;
            AttributeNode attr = p.GetAttribute(SystemTypes.WriteConfinedAttribute);

            if (attr != null)
            {
                WriteConfinedAttribute wAttr = (WriteConfinedAttribute)attr.GetRuntimeAttribute();
                res = wAttr.Value;
            }
            else
            {
                res = false;
            }
            // res = p.GetAttribute(SystemTypes.WriteConfinedAttribute) != null;
            return(res);
        }
Exemplo n.º 2
0
        public static bool IsDeclaredWritingGlobals(Method m)
        {
            if (WorstCase)
            {
                return(true);
            }

            bool res = false;

            AttributeNode attr = m.GetAttribute(SystemTypes.GlobalWriteAttribute);

            if (attr != null)
            {
                GlobalWriteAttribute writeAttr = (GlobalWriteAttribute)attr.GetRuntimeAttribute();
                if (writeAttr != null)
                {
                    res = writeAttr.Value;
                }
            }
            else
            {
                if (!IsDeclaredAccessingGlobals(m))
                {
                    return(false);
                }
                if (IsAssumedPureMethod(m) ||
                    IsDeclaredWriteConfined(m))
                {
                    return(false);
                }
            }
            return(res);
        }
Exemplo n.º 3
0
        public static bool IsDeclaredRead(Parameter p)
        {
            if (WorstCase)
            {
                return(true);
            }
            bool          res  = true;
            AttributeNode attr = p.GetAttribute(SystemTypes.ReadAttribute);

            if (attr != null)
            {
                ReadAttribute rAttr = (ReadAttribute)attr.GetRuntimeAttribute();
                res = rAttr.Value;
            }
            return(res);
        }
Exemplo n.º 4
0
        public static bool IsPurityForcedByUser(Method method)
        {
            if (WorstCase)
            {
                return(false);
            }
            bool          res  = false;
            AttributeNode attr = method.GetAttribute(SystemTypes.PureAttribute);

            if (attr != null)
            {
                PureAttribute purity = (PureAttribute)attr.GetRuntimeAttribute();
                if (purity != null)
                {
                    return(purity.IsAssumedPure);
                }
            }

            return(res);
        }
Exemplo n.º 5
0
        public static bool IsDeclaredWrite(Parameter p)
        {
            if (WorstCase)
            {
                return(true);
            }
            bool          res  = true;
            AttributeNode attr = p.GetAttribute(SystemTypes.WriteAttribute);

            if (attr != null)
            {
                WriteAttribute wAttr = (WriteAttribute)attr.GetRuntimeAttribute();
                res = wAttr.Value;
            }
            else
            {
                res = true;
            }

            return(res);
        }
Exemplo n.º 6
0
        public static bool IsDeclaredEscaping(Parameter p, out bool owned)
        {
            if (WorstCase)
            {
                owned = true;
                return(true);
            }
            bool res = false;

            owned = false;
            if (p.GetAttribute(SystemTypes.CapturedAttribute) != null)
            {
                owned = true;
                return(true);
            }
            if (p is This)
            {
                Method m = ((This)p).DeclaringMethod;
                return(IsEscaping(m, out owned));
            }
            AttributeNode attr = p.GetAttribute(SystemTypes.EscapesAttribute);

            if (attr != null)
            {
                Microsoft.Contracts.EscapesAttribute escAttr = (Microsoft.Contracts.EscapesAttribute)attr.GetRuntimeAttribute();
                if (escAttr != null)
                {
                    res   = escAttr.Value;
                    owned = escAttr.Owned;
                }
            }
            return(res);
        }
Exemplo n.º 7
0
        public static bool IsEscaping(Method m, out bool owned)
        {
            if (WorstCase)
            {
                owned = true;
                return(true);
            }

            bool res = false;

            owned = false;
            if (!m.IsStatic)
            {
                if (m.GetAttribute(SystemTypes.CapturedAttribute) != null)
                {
                    owned = true;
                    return(true);
                }
            }
            AttributeNode attr = m.GetAttribute(SystemTypes.EscapesAttribute);

            if (attr != null)
            {
                Microsoft.Contracts.EscapesAttribute escAttr = (Microsoft.Contracts.EscapesAttribute)attr.GetRuntimeAttribute();
                if (escAttr != null)
                {
                    res   = escAttr.Value;
                    owned = escAttr.Owned;
                }
            }
            return(res && !IsConstructor(m));
        }
Exemplo n.º 8
0
        public static bool IsDeclaredAccessingGlobals(Method m)
        {
            if (WorstCase)
            {
                return(true);
            }

            bool res = true;


            AttributeNode attr = m.GetAttribute(SystemTypes.GlobalAccessAttribute);

            if (attr != null)
            {
                Microsoft.Contracts.GlobalAccessAttribute readAttr = (Microsoft.Contracts.GlobalAccessAttribute)attr.GetRuntimeAttribute();
                if (readAttr != null)
                {
                    res = readAttr.Value;
                }
            }
            else
            {
                if (IsAssumedConfinedMethod(m))
                {
                    return(false);
                }

                // We assume thet constructor are not writing globals
                if (CciHelper.IsConstructor(m))
                {
                    res = false;
                }

                //if (m.DeclaringType != null && CciHelper.IsInterface(m.DeclaringType)
                //    && m.DeclaringType.FullName.StartsWith("System.Collections"))
                //    return false;
            }
            return(res);
        }