private static void ProcessMethod(CCCheckOutputAssemblyMethod method, List <BaseAnnotation> annotations) { if (method.Name.EndsWith("..cctor")) { Output.WriteLine("Ignoring suggestions for {0} as it is a static constructor", method.Name); return; } if (method.Suggestion == null) { #if DEBUG_PRINT Output.WriteLine("No suggestions for method {0}", method.Name); #endif return; } foreach (var suggestion in method.Suggestion) { Contract.Assume(suggestion != null); string path, whyFailed = null; Squiggle squiggle; BaseAnnotation ann; ClousotSuggestion.Kind suggestionKind; if (Enum.TryParse(suggestion.SuggestionKind, out suggestionKind) && TryGetPath(suggestion.SourceLocation, out path, out squiggle, out whyFailed) && AnnotationFactory.TryMakeAnnotation(method, suggestion, suggestionKind, path, squiggle, out ann, out whyFailed)) { annotations.Add(ann); } else { Output.WriteError("Failed to parse suggestion for {0}. Reason {1}", method.Name, whyFailed); } } }
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; } } }
private static void ProcessMethod(CCCheckOutputAssemblyMethod method, List<BaseAnnotation> annotations) { if (method.Name.EndsWith("..cctor")) { Output.WriteLine("Ignoring suggestions for {0} as it is a static constructor", method.Name); return; } if (method.Suggestion == null) { #if DEBUG_PRINT Output.WriteLine("No suggestions for method {0}", method.Name); #endif return; } foreach (var suggestion in method.Suggestion) { Contract.Assume(suggestion != null); string path, whyFailed = null; Squiggle squiggle; BaseAnnotation ann; ClousotSuggestion.Kind suggestionKind; if (Enum.TryParse(suggestion.SuggestionKind, out suggestionKind) && TryGetPath(suggestion.SourceLocation, out path, out squiggle, out whyFailed) && AnnotationFactory.TryMakeAnnotation(method, suggestion, suggestionKind, path, squiggle, out ann, out whyFailed)) { annotations.Add(ann); } else { Output.WriteError("Failed to parse suggestion for {0}. Reason {1}", method.Name, whyFailed); } } }