public ResolvedObjectInvariant(UnresolvedObjectInvariant original, string filename, string methodname) : base(filename, methodname, original.Annotation, original.Squiggle, original.Kind) { #region CodeContracts Contract.Requires(original != null); Contract.Requires(filename != null); Contract.Requires(methodname != null); Contract.Ensures(this.FileName == filename); Contract.Ensures(this.MethodName == methodname); Contract.Ensures(this.OriginalAnnotation == original); #endregion CodeContracts this.OriginalAnnotation = original; }
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); } } }
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; } } }