Exemple #1
0
    public static bool TryMakeAnnotation(CCCheckOutputAssemblyMethod method,
                                         CCCheckOutputAssemblyMethodSuggestion suggestion,
                                         ClousotSuggestion.Kind suggestionKind,
                                         string path,
                                         Squiggle squiggle,
                                         out BaseAnnotation annotation, out string whyFailed)
    {
      #region CodeContracts
      Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out annotation) != null);
      Contract.Ensures(Contract.Result<bool>() || Contract.ValueAtReturn(out whyFailed) != null);
      #endregion CodeContracts

      whyFailed = null;
      annotation = null;
      switch (suggestionKind)
      {
        case ClousotSuggestion.Kind.AssumeOnEntry:
        case ClousotSuggestion.Kind.Ensures:
        case ClousotSuggestion.Kind.Requires:
          {
            annotation = new Precondition(path, method.Name, suggestion.Suggested, squiggle, suggestionKind);
            return true;
          }

        case ClousotSuggestion.Kind.ObjectInvariant:
          {
            Contract.Assert(suggestion.SuggestionExtraInfo != null, "We expect to have extra info for the suggestion of an object invariant");
            var exinfo2 = suggestion.SuggestionExtraInfo[0];
            annotation = new UnresolvedObjectInvariant(path, method.Name, exinfo2.TypeDocumentId, exinfo2.SuggestedCode, squiggle, suggestionKind);
            return true;
          }

        case ClousotSuggestion.Kind.EnsuresNecessary:
          {
            Contract.Assert(suggestion.SuggestionExtraInfo != null, "We expect to have extra info for the suggestion of an ensures necessary");
            if (suggestion.SuggestionExtraInfo.First().CalleeMemberKind == "Interface")
            {
              var exinfo = suggestion.SuggestionExtraInfo[0];
              if (exinfo.CalleeIsDeclaredInTheSameAssembly.Equals("False"))
              {
                whyFailed = "Don't know what to do when callee is in another assembly";
                return false;
              }
              //annotation = new UnresolvedInterfaceAnnotation(exinfo, squiggle, suggestionKind);
              UnresolvedInterfaceAnnotation ann;
              if (InterfaceAnnotationHelpers.TryMakeUnresolvedInterfaceAnnotation(exinfo, squiggle, suggestionKind, out ann))
              {
                annotation = ann;
                return true;
              }
              whyFailed = "Unknown suggestion";
              return false;
            }
            whyFailed = string.Format("Unhandled clousot suggestion kind {0} {1}", suggestionKind, suggestion.SuggestionExtraInfo.First().CalleeMemberKind);
            return false;
          }

        case ClousotSuggestion.Kind.ReadonlyField:
          {
            Contract.Assert(suggestion.SuggestionExtraInfo != null, "We expect to have extra info for the suggestion of a readonly field");
            var extraInfo = suggestion.SuggestionExtraInfo[0];
            annotation = new ReadonlyField(extraInfo.CalleeDocumentId, path, extraInfo.TypeDocumentId, method.Name, squiggle, ClousotSuggestion.Kind.ReadonlyField);
            return true;
          }

        default:
          {
            whyFailed = string.Format("Unhandled clousot suggestion kind {0}", suggestionKind);
            return false;
          }
      }
    }
Exemple #2
0
        public static bool TryMakeAnnotation(CCCheckOutputAssemblyMethod method,
                                             CCCheckOutputAssemblyMethodSuggestion suggestion,
                                             ClousotSuggestion.Kind suggestionKind,
                                             string path,
                                             Squiggle squiggle,
                                             out BaseAnnotation annotation, out string whyFailed)
        {
            #region CodeContracts
            Contract.Ensures(!Contract.Result <bool>() || Contract.ValueAtReturn(out annotation) != null);
            Contract.Ensures(Contract.Result <bool>() || Contract.ValueAtReturn(out whyFailed) != null);
            #endregion CodeContracts

            whyFailed  = null;
            annotation = null;
            switch (suggestionKind)
            {
            case ClousotSuggestion.Kind.AssumeOnEntry:
            case ClousotSuggestion.Kind.Ensures:
            case ClousotSuggestion.Kind.Requires:
            {
                annotation = new Precondition(path, method.Name, suggestion.Suggested, squiggle, suggestionKind);
                return(true);
            }

            case ClousotSuggestion.Kind.ObjectInvariant:
            {
                Contract.Assert(suggestion.SuggestionExtraInfo != null, "We expect to have extra info for the suggestion of an object invariant");
                var exinfo2 = suggestion.SuggestionExtraInfo[0];
                annotation = new UnresolvedObjectInvariant(path, method.Name, exinfo2.TypeDocumentId, exinfo2.SuggestedCode, squiggle, suggestionKind);
                return(true);
            }

            case ClousotSuggestion.Kind.EnsuresNecessary:
            {
                Contract.Assert(suggestion.SuggestionExtraInfo != null, "We expect to have extra info for the suggestion of an ensures necessary");
                if (suggestion.SuggestionExtraInfo.First().CalleeMemberKind == "Interface")
                {
                    var exinfo = suggestion.SuggestionExtraInfo[0];
                    if (exinfo.CalleeIsDeclaredInTheSameAssembly.Equals("False"))
                    {
                        whyFailed = "Don't know what to do when callee is in another assembly";
                        return(false);
                    }
                    //annotation = new UnresolvedInterfaceAnnotation(exinfo, squiggle, suggestionKind);
                    UnresolvedInterfaceAnnotation ann;
                    if (InterfaceAnnotationHelpers.TryMakeUnresolvedInterfaceAnnotation(exinfo, squiggle, suggestionKind, out ann))
                    {
                        annotation = ann;
                        return(true);
                    }
                    whyFailed = "Unknown suggestion";
                    return(false);
                }
                whyFailed = string.Format("Unhandled clousot suggestion kind {0} {1}", suggestionKind, suggestion.SuggestionExtraInfo.First().CalleeMemberKind);
                return(false);
            }

            case ClousotSuggestion.Kind.ReadonlyField:
            {
                Contract.Assert(suggestion.SuggestionExtraInfo != null, "We expect to have extra info for the suggestion of a readonly field");
                var extraInfo = suggestion.SuggestionExtraInfo[0];
                annotation = new ReadonlyField(extraInfo.CalleeDocumentId, path, extraInfo.TypeDocumentId, method.Name, squiggle, ClousotSuggestion.Kind.ReadonlyField);
                return(true);
            }

            default:
            {
                whyFailed = string.Format("Unhandled clousot suggestion kind {0}", suggestionKind);
                return(false);
            }
            }
        }
Exemple #3
0
 //public FieldSplitterRewriter (IEnumerable<ReadonlyField> annotations, SyntaxTree st, Compilation compilation) 
 public FieldSplitterRewriter (ReadonlyField annotation, SyntaxTree st, Compilation compilation) 
 {
   //this.annotations = annotations;
   this.annotation = annotation;
   this.SemanticModel = compilation.GetSemanticModel(st);
   this.AnnotationDCI = annotation.FieldName.Replace("F:", "");
   //this.annotationDCIs = annotations.Select(x => x.FieldName.Replace("F:",""));
   this.Compilation = compilation;
 }