コード例 #1
0
        // We have this static as we want to share some code with the AssertionCrawler
        public string AddHintsForTheUser(ProofOutcome outcome, string format, Set <WarningContext> context)
        {
            Contract.Requires(format != null);
            Contract.Ensures(Contract.Result <string>() != null);

            return(outcome != ProofOutcome.True ? SuggestAddingPrecondition(format, context) : format);
        }
コード例 #2
0
 protected override void PopulateWarningContextInternal(ProofOutcome outcome)
 {
     if (outcome == ProofOutcome.Top)
     {
         this.AdditionalInformationOnTheWarning.AddRange(WarningContextFetcher.InferContext(this.PC, this.index, this.Context, this.DecoderForMetaData.IsBoolean));
     }
 }
コード例 #3
0
 public SearchResult(int line, int col, BaseMethodDeclarationSyntax method, ProofOutcome outcome)
 {
     this.Line    = line;
     this.Column  = col;
     this.Method  = method;
     this.Outcome = outcome;
 }
コード例 #4
0
        protected string AddHintsForTheUser(ProofOutcome outcome, string format)
        {
            Contract.Requires(format != null);
            Contract.Ensures(Contract.Result <string>() != null);

            return(AddHintsForTheUser(outcome, format, this.AdditionalInformationOnTheWarning));
        }
コード例 #5
0
            static string CanonicalFormat(string methodName, WarningKind kind, ProofOutcome outcome, string message, int primaryILOffset, int methodILOffset, BaseLiningOptions baselineStrategy)
            {
                switch (baselineStrategy)
                {
                case BaseLiningOptions.ilBased:
                    return(String.Format("{0}:{1} PrimaryIL={2} MethodIL={3}", methodName, message, primaryILOffset, methodILOffset));

                case BaseLiningOptions.typeBased:
                    return(String.Format("{0}:{1}", methodName, kind.ToString()));

                case BaseLiningOptions.mixed:
                default:
                    switch (kind)
                    {
                    case WarningKind.Invariant:
                    case WarningKind.Assert:
                    case WarningKind.Requires:
                    case WarningKind.Ensures:
                        return(String.Format("{0} PrimaryIL={1}", message, primaryILOffset));

                    default:
                        return(message);
                    }
                }
            }
コード例 #6
0
    public ProofOutcome AddObjectInvariants(ProofObligation obl, IEnumerable<BoxedExpression> objectInvariants, ProofOutcome originalOutcome)
    {
      Contract.Requires(obl != null);
      Contract.Requires(objectInvariants != null);

      return ProofOutcome.Top;
    }
コード例 #7
0
        public void UpdateCounter(ProofOutcome outcome)
        {
            Contract.Assert(0 <= outcome);
            Contract.Assume((int)outcome < counter.Length);

            counter[(int)outcome]++;
        }
コード例 #8
0
        public void UpdateCounter(ProofOutcome outcome)
        {
            Contract.Assert(0 <= outcome);
            Contract.Assume((int)outcome < this.counter.Length);

            this.counter[(int)outcome]++;
        }
コード例 #9
0
        internal string GetMessageString(ProofOutcome outcome, string p)
        {
            // var msg = ProofObligationBase<BoxedExpression, Variable>.AddHintsForTheUser(outcome, p, this.GetWarningContext);

            // Add some information from the provenance, i.e., a sequence of calls
            var msg = ImproveMessageForInferredConditions(p, outcome);

            // Get information from the entry state
            var msgFromCodeFixes = GetMessageStringFromCodeFixesOrSufficientButNotNecessaryConditions();

            // Get information from the output message
            var msgViaOutParam = GetMessageFromWarningContexts();

            // Now let's build the string
            char c;
            var  sep = (msg != null && ((c = msg[msg.Length - 1]) != '}' && Char.IsPunctuation(c))) ? " " : ". ";

            var tempString1 = !string.IsNullOrEmpty(msgFromCodeFixes)
        ? msg + sep + msgFromCodeFixes
        : msg;

            return(msgViaOutParam != null
        ? string.Format("{0}{1}{2}", tempString1, sep, msgViaOutParam)
        : tempString1);
        }
コード例 #10
0
 public override int SwallowedMessagesCount(ProofOutcome outcome)
 {
     if (ok)
     {
         return(base.SwallowedMessagesCount(outcome));
     }
     return(0);
 }
コード例 #11
0
        public static ProofOutcome Join(this ProofOutcome o1, ProofOutcome o2)
        {
            if (o1 == o2) return o1;
            if (o1 == ProofOutcome.Top || o2 == ProofOutcome.Bottom) return o1;
            if (o2 == ProofOutcome.Top || o1 == ProofOutcome.Bottom) return o2;

            // different and none is top or bottom, so join of true and false
            return ProofOutcome.Top;
        }
コード例 #12
0
		public static ProofOutcome Join (this ProofOutcome a, ProofOutcome b)
		{
			if (a == b || a == ProofOutcome.Top || b == ProofOutcome.Bottom)
				return a;
			if (b == ProofOutcome.Top || a == ProofOutcome.Bottom)
				return b;

			return ProofOutcome.Top;
		}
コード例 #13
0
        public ProofOutcome Isinst(E orig, TypeNode type, V dest, E obj, bool polarity)
        {
            if (!polarity)
            {
                return(this.analysis.IsNull(this.pc, dest));
            }
            ProofOutcome outcome = this.analysis.IsNonNull(this.pc, dest);

            return(outcome != ProofOutcome.True ? outcome : this.Recurse(true, obj));
        }
コード例 #14
0
        public Witness(uint?sourceProofObligation, WarningType warning, ProofOutcome outcome, APC PC, Set <WarningContext> context, ClousotSuggestion.Kind?type = null)
        {
            Contract.Requires(context != null);

            this.SourceProofObligationID = sourceProofObligation;
            this.PC      = PC;
            this.Outcome = outcome;
            this.Warning = warning;
            this.Context = context;
            this.TypeOfSuggestionTurnedIntoWarning = type;
        }
コード例 #15
0
		public static ProofOutcome Meet (this ProofOutcome a, ProofOutcome b)
		{
			if (a == b)
				return a;
			if (a == ProofOutcome.Top || b == ProofOutcome.Bottom)
				return b;
			if (b == ProofOutcome.Top || a == ProofOutcome.Bottom)
				return a;

			return ProofOutcome.Bottom;
		}
コード例 #16
0
        protected override void PopulateWarningContextInternal(ProofOutcome outcome)
        {
            if (this.MethodMayContainUnsafeCode.HasValue && (this.MethodMayContainUnsafeCode.Value == true))
            {
                this.AdditionalInformationOnTheWarning.Add(new WarningContext(WarningContext.ContextType.InsideUnsafeMethod));
            }

            if (this.MayBeAStringNullComparisonInASwitchStatement.HasValue && this.MayBeAStringNullComparisonInASwitchStatement.Value)
            {
                this.AdditionalInformationOnTheWarning.Add(new WarningContext(WarningContext.ContextType.StringComparedAgainstNullInSwitchStatement));
            }
        }
コード例 #17
0
        public override void EmitOutcome(ProofOutcome outcome, IOutputResults output)
        {
            // For some reason the EmitOutcome for the other assertions is done externally
            if (this.IsConditionCheck)
            {
                this.PopulateWarningContextInternal(outcome);
                var witness = this.GetWitness(outcome);

                // new Witness(this.ID, WarningType.TestAlwaysEvaluatingToAConstant, ProofOutcome.Bottom, this.PC)
                output.EmitOutcome(witness, MessageString(), this.condition.ToString());
            }
        }
コード例 #18
0
        public bool CheckPreconditionAndCanAddRequires(BoxedExpression condition, ProofOutcome pre, out ProofOutcome outcome)
        {
            Contract.Requires(condition != null);

            if (!this.mdriver.CanAddRequires())
            {
                outcome = pre;
                return(false);
            }

            return(base.CheckPrecondition(condition, pre, out outcome));
        }
コード例 #19
0
ファイル: SimpleLogicInference.cs プロジェクト: raj581/Marvin
        public override ProofOutcome IsNonNull(APC pc, BoxedExpression expr)
        {
            Variable v;

            if (TryVariable(expr, out v))
            {
                ProofOutcome proofOutcome = this.FactBase.IsNonNull(pc, v);
                if (proofOutcome != ProofOutcome.Top)
                {
                    return(proofOutcome);
                }
            }

            if (expr.IsConstant)
            {
                object constant = expr.Constant;
                if (constant == null)
                {
                    return(ProofOutcome.False);
                }
                if (constant is string)
                {
                    return(ProofOutcome.True);
                }
                var convertible = constant as IConvertible;
                if (convertible != null)
                {
                    try {
                        return((convertible.ToInt64(null) == 0) ? ProofOutcome.False : ProofOutcome.True);
                    } catch {
                        return(ProofOutcome.Top);
                    }
                }
            }

            BinaryOperator  op;
            BoxedExpression left;
            BoxedExpression right;

            if (expr.IsBinaryExpression(out op, out left, out right))
            {
                if ((op == BinaryOperator.Ceq || op == BinaryOperator.Cobjeq) && IsNull(pc, right) == ProofOutcome.True)
                {
                    return(IsNull(pc, left));
                }
                if (op == BinaryOperator.Cne_Un && IsNull(pc, right) == ProofOutcome.True)
                {
                    return(IsNonNull(pc, left));
                }
            }
            return(ProofOutcome.Top);
        }
コード例 #20
0
        public void Add(ProofObligation obl, BoxedExpression exp, ProofOutcome outcome)
        {
            Contract.Requires(obl != null);
            Contract.Requires(exp != null);

            this.inferred.Add(new Tuple <BoxedExpression, string, ProofOutcome, List <ProofObligation> >(exp, exp.ToString(), outcome, new List <ProofObligation>()
            {
                obl
            }));

            // we added a new condition, let us discare the previous ones
            this.preconditions = null;
        }
コード例 #21
0
        private void EmitOutcomeToBaseLine(WarningKind kind, ProofOutcome outcome, APC pc, string message)
        {
            int primaryILOffset, methodILOffset;

            GetILOffsets(pc, this.currentMethod, out primaryILOffset, out methodILOffset);
            xmlWriter.WriteStartElement("Outcome");
            xmlWriter.WriteAttributeString("Kind", kind.ToString());
            xmlWriter.WriteAttributeString("Outcome", outcome.ToString());
            xmlWriter.WriteAttributeString("Message", message);
            xmlWriter.WriteAttributeString("PrimaryILOffset", primaryILOffset.ToString("x"));
            xmlWriter.WriteAttributeString("MethodILOffset", methodILOffset.ToString("x"));
            xmlWriter.WriteEndElement();
        }
コード例 #22
0
        public override Witness GetWitness(ProofOutcome outcome)
        {
            var warningType = this.IsConditionCheck? WarningType.TestAlwaysEvaluatingToAConstant: TagToWarningType(this.Tag);

            var witness = new Witness(this.ID, warningType, outcome, this.PC, this.AdditionalInformationOnTheWarning);

            if (this.ShowInferenceTrace)
            {
                WalkProvenance(this, 0, witness);
            }

            return(witness);
        }
コード例 #23
0
        public static ProofOutcome Join(this ProofOutcome a, ProofOutcome b)
        {
            if (a == b || a == ProofOutcome.Top || b == ProofOutcome.Bottom)
            {
                return(a);
            }
            if (b == ProofOutcome.Top || a == ProofOutcome.Bottom)
            {
                return(b);
            }

            return(ProofOutcome.Top);
        }
コード例 #24
0
 public bool TryLookUp(ProofObligation obligation, BoxedExpression expression, out ProofOutcome outcome)
 {
     string s = ((object)expression).ToString ();
     foreach (Tuple<BoxedExpression, string, ProofOutcome, List<ProofObligation>> item in this.inferred) {
         if (item.Item2 == s) {
             item.Item4.Add (obligation);
             outcome = item.Item4;
             return true;
         }
     }
     outcome = ProofOutcome.Top;
     return false;
 }
コード例 #25
0
ファイル: BasicFacts.cs プロジェクト: raj581/Marvin
        public ProofOutcome IsTrueImply(APC pc, LispList <BoxedExpression> positiveAssumptions, LispList <BoxedExpression> negativeAssumptions, BoxedExpression goal)
        {
            ProofOutcome outcome = IsTrue(pc, goal);

            switch (outcome)
            {
            case ProofOutcome.True:
            case ProofOutcome.Bottom:
                return(outcome);

            default:
                return(ProofOutcome.Top);
            }
        }
コード例 #26
0
ファイル: BasicFacts.cs プロジェクト: raj581/Marvin
        public virtual ProofOutcome IsNonNull(APC pc, BoxedExpression expr)
        {
            Variable v;

            if (TryVariable(expr, out v))
            {
                ProofOutcome outcome = this.FactBase.IsNonNull(pc, v);
                if (outcome != ProofOutcome.Top)
                {
                    return(outcome);
                }
            }
            return(ProofOutcome.Top);
        }
コード例 #27
0
        protected static ClousotRegression.ProofOutcome Translate(ProofOutcome outcome)
        {
            switch (outcome)
            {
            case ProofOutcome.Bottom: return(Microsoft.Research.ClousotRegression.ProofOutcome.Bottom);

            case ProofOutcome.False: return(Microsoft.Research.ClousotRegression.ProofOutcome.False);

            case ProofOutcome.Top: return(Microsoft.Research.ClousotRegression.ProofOutcome.Top);

            case ProofOutcome.True: return(Microsoft.Research.ClousotRegression.ProofOutcome.True);

            default: throw new NotImplementedException();
            }
        }
コード例 #28
0
        protected bool CheckPrecondition(BoxedExpression simplified, ProofOutcome originalOutcome, out ProofOutcome outcome)
        {
            Contract.Requires(simplified != null);

            outcome = originalOutcome;

            if (this.output.LogOptions.PropagateInferredRequires(mdriver.MetaDataDecoder.IsPropertyGetterOrSetter(mdriver.CurrentMethod)))
            {
                if (this.output.LogOptions.PropagatedRequiresAreSufficient)
                {
                    outcome = ProofOutcome.True;
                }
            }

            return(true);
        }
コード例 #29
0
        public ProofOutcome AddPreconditionOrAssume(ProofObligation obl, IEnumerable<BoxedExpression> conditions, ProofOutcome outcome = ProofOutcome.Top)
        {
            Contract.Requires(conditions != null);
            Contract.Requires(obl != null);

            if (this.CanAddPreconditions)
            {
                Contract.Assume(this.PreCondition.Dispatch != null);
                return this.PreCondition.Dispatch.AddPreconditions(obl, conditions, outcome);
            }
            else
            {
                this.Assumptions.AddEntryAssumes(obl, conditions);
                this.OverriddenMethodPreconditionDispatcher.AddPotentialPreconditions(obl, conditions);

                return outcome;
            }
        }
コード例 #30
0
            public bool TryLookUp(BoxedExpression exp, out ProofOutcome outcome)
            {
                Contract.Requires(exp != null);

                var expStr = exp.ToString();

                foreach (var triple in this.inferred)
                {
                    if (triple.Item2 == expStr)
                    {
                        outcome = triple.Item3;
                        return(true);
                    }
                }
                outcome = ProofOutcome.Top;

                return(false);
            }
コード例 #31
0
        public static ProofOutcome Join(this ProofOutcome o1, ProofOutcome o2)
        {
            if (o1 == o2)
            {
                return(o1);
            }
            if (o1 == ProofOutcome.Top || o2 == ProofOutcome.Bottom)
            {
                return(o1);
            }
            if (o2 == ProofOutcome.Top || o1 == ProofOutcome.Bottom)
            {
                return(o2);
            }

            // different and none is top or bottom, so join of true and false
            return(ProofOutcome.Top);
        }
コード例 #32
0
        public static ProofOutcome Negate(this ProofOutcome o)
        {
            switch (o)
            {
            case ProofOutcome.Top:
            case ProofOutcome.Bottom:
                return(o);

            case ProofOutcome.True:
                return(ProofOutcome.False);

            case ProofOutcome.False:
                return(ProofOutcome.True);

            default:
                return(ProofOutcome.Top);
            }
        }
コード例 #33
0
            static string Canonicalize(String methodName, XElement outcomeElement, BaseLiningOptions baselineStrategy)
            {
                var outcomeKind = (string)outcomeElement.Attribute("Outcome");

                if (outcomeKind != null)
                {
                    ProofOutcome outcome         = (ProofOutcome)Enum.Parse(typeof(ProofOutcome), (string)outcomeElement.Attribute("Outcome"), true);
                    WarningKind  kind            = (WarningKind)Enum.Parse(typeof(WarningKind), (string)outcomeElement.Attribute("Kind"), true);
                    string       message         = (string)outcomeElement.Attribute("Message");
                    int          primaryILOffset = Int32.Parse((string)outcomeElement.Attribute("PrimaryILOffset"), System.Globalization.NumberStyles.HexNumber);
                    int          methodILOffset  = Int32.Parse((string)outcomeElement.Attribute("MethodILOffset"), System.Globalization.NumberStyles.HexNumber);
                    return(CanonicalFormat(methodName, kind, outcome, message, primaryILOffset, methodILOffset, baselineStrategy));
                }
                else
                {
                    return((string)outcomeElement.Attribute("Message"));
                }
            }
コード例 #34
0
        protected ProofOutcome GenericAddPreconditions(ProofObligation obl, IEnumerable <BoxedExpression> preconditions, ProofOutcome originalOutcome,
                                                       InferenceDB preconditionDB, PreconditionChecker checkPrecondition)
        {
            var outcome = originalOutcome;

            foreach (var pre in preconditions)
            {
                if (pre == null)
                {
                    continue;
                }

                // 1. Simplify the expression
                var simplified = SimplifyAndFix(obl.PCForValidation, pre);

                if (simplified == null)
                {
                    continue;
                }

                if (DisjunctivePreconditionsAreDisallowed(simplified))
                {
                    continue;
                }

                // 2. Have we already seen this precondition?
                if (preconditionDB.TryLookUp(obl, simplified, out outcome))
                {
                    continue;
                }
                else
                {
                    outcome = originalOutcome;
                }

                // 3. See if it is valid
                if (checkPrecondition(simplified, outcome, out outcome))
                {
                    preconditionDB.Add(obl, simplified, outcome);
                }
            }

            return(outcome);
        }
コード例 #35
0
    public bool TryLookUp(ProofObligation obl, BoxedExpression exp, out ProofOutcome outcome)
    {
      Contract.Requires(obl != null);
      Contract.Requires(exp != null);

      var expStr = exp.ToString();
      foreach (var quad in this.inferred)
      {
        if (quad.Item2 == expStr)
        {
          quad.Item4.Add(obl);
          outcome = quad.Item3;
          return true;
        }
      }
      outcome = ProofOutcome.Top;

      return false;
    }
コード例 #36
0
                protected string FixedMessages(ProofOutcome outcome)
                {
                    switch (outcome)
                    {
                    case ProofOutcome.Bottom:
                        return("This arithmetic operation is unreached");

                    case ProofOutcome.False:
                        return(What + " in the arithmetic operation");

                    case ProofOutcome.Top:
                        return("Possible " + what + " in the arithmetic operation");

                    case ProofOutcome.True:
                        return("No " + what);

                    default:
                        return("unknown outcome");
                    }
                }
コード例 #37
0
                    public override void EmitOutcome(ProofOutcome outcome, IOutputResults output)
                    {
                        Contract.Assume(output != null, "Should be a precondition");

                        var index = (int)outcome;

                        if (index < 0 || index >= fixedMessagesWrite.Length)
                        {
                            return;
                        }

                        if (this.isWrite)
                        {
                            output.EmitOutcome(GetWitness(outcome), AddHintsForTheUser(outcome, "{0}"), fixedMessagesWrite[index]);
                        }
                        else
                        {
                            output.EmitOutcome(GetWitness(outcome), AddHintsForTheUser(outcome, "{0}"), fixedMessagesRead[index]);
                        }
                    }
コード例 #38
0
        public bool TryLookUp(ProofObligation obl, BoxedExpression exp, out ProofOutcome outcome)
        {
            Contract.Requires(obl != null);
            Contract.Requires(exp != null);

            var expStr = exp.ToString();

            foreach (var quad in this.inferred)
            {
                if (quad.Item2 == expStr)
                {
                    quad.Item4.Add(obl);
                    outcome = quad.Item3;
                    return(true);
                }
            }
            outcome = ProofOutcome.Top;

            return(false);
        }
コード例 #39
0
ファイル: Options.cs プロジェクト: asvishnyakov/CodeContracts
    public bool PrintOutcome(ProofOutcome outcome)
    {
      switch (outcome) {
        case ProofOutcome.True:
          return this.show.Contains(ShowOptions.validations);

        case ProofOutcome.Bottom:
          return
            this.show.Contains(ShowOptions.validations) ||
            this.show.Contains(ShowOptions.unreached);

        case ProofOutcome.False:
        case ProofOutcome.Top:
          return this.show.Contains(ShowOptions.errors);

        default:
          return true;
      }
    }
コード例 #40
0
    private double GetScoreForOutcome(ProofOutcome proofOutcome)
    {
      switch (proofOutcome)
      {
        #region All the cases
        case ProofOutcome.Bottom:
          return this.ScoreBottom;

        case ProofOutcome.False:
          return this.ScoreFalse;

        case ProofOutcome.Top:
          return this.ScoreTop;

        case ProofOutcome.True:
          return this.ScoreTrue;

        default:
          // should be unreachable
#if DEBUG
          Contract.Assert(false);
#endif

          return 0.0;
        #endregion
      }
    }
コード例 #41
0
    public void Add(ProofObligation obl, BoxedExpression exp, ProofOutcome outcome)
    {
      Contract.Requires(obl != null);
      Contract.Requires(exp != null);

      this.inferred.Add(new Tuple<BoxedExpression, string, ProofOutcome, List<ProofObligation>>(exp, exp.ToString(), outcome, new List<ProofObligation>() { obl }));

      // we added a new condition, let us discare the previous ones
      this.preconditions = null; 
    }
コード例 #42
0
 public int GetCounter(ProofOutcome outcome)
 {
     Contract.Assert(0 <= outcome);
     Contract.Assume((int)outcome < counter.Length);
     return counter[(int)outcome];
 }
コード例 #43
0
 public int GetCounter(ProofOutcome outcome)
 {
     return this.counter[(int) outcome];
 }
コード例 #44
0
 public void UpdateCounter(ProofOutcome outcome)
 {
     ++this.counter[(int) outcome];
 }
コード例 #45
0
 public ProofOutcome AddObjectInvariants(ProofObligation obl, IEnumerable<BoxedExpression> objectInvariants, ProofOutcome originalOutcome)
 {
   generated += objectInvariants.Count();
   return this.inner.AddObjectInvariants(obl, objectInvariants, originalOutcome);
 }
コード例 #46
0
        public void Add(ProofOutcome color, uint howMany = 1)
        {
            Contract.Requires(howMany > 0);

            switch (color)
            {
                case ProofOutcome.Bottom:
                    this.Bottom += howMany;
                    break;
                case ProofOutcome.Top:
                    this.Top += howMany;
                    break;
                case ProofOutcome.True:
                    this.True += howMany;
                    break;
                case ProofOutcome.False:
                    this.False += howMany;
                    break;
            }
            this.Total += howMany;
        }
コード例 #47
0
 public ProofOutcome AddPreconditions(ProofObligation obl, IEnumerable<BoxedExpression> preconditions, ProofOutcome originalOutcome)
 {
     return originalOutcome;
 }
コード例 #48
0
 public void Add(ProofObligation obligation, BoxedExpression expression, ProofOutcome outcome)
 {
     this.inferred.Add (new Tuple<BoxedExpression, string, ProofOutcome, List<ProofObligation>> (expression, ((object)expression).ToString (), outcome, new List<ProofObligation> (){obligation}));
     this.preconditions = (Dictionary<BoxedExpression, List<ProofObligation>>)null;
 }