public override void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List <uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { if (this.isMethodOk) { base.Suggestion(type, kind, pc, suggestion, causes, extraInfo); } }
//public UnresolvedInterfaceAnnotation( // CCCheckExtraInfo extra_info, // Squiggle squiggle, // ClousotSuggestion.Kind kind) // : base(null, null, extra_info.SuggestedCode, squiggle, kind) //{ // // TODO there are ways this can fail to create a valid annotation // // there is a lot of string parsing going on that could go wrong // // could be refactored into a TryXXXX? // //this.extraInfo = extra_info; // this.InterfaceMethod = extra_info.CalleeDocumentId; // this.InterfaceName = extra_info.TypeDocumentId; // if (InterfaceName.Contains('<')) // { // var lastAngle = InterfaceName.LastIndexOf('<'); // var beforeAngle = InterfaceName.Remove(lastAngle); // var afterAngle = InterfaceName.Replace(beforeAngle, ""); // InterfaceName = beforeAngle; // var parts = afterAngle.Trim('<', '>').Split(','); // NumberParameters = parts.Count(); // ParametersString = "<" + parts[0].Replace("type parameter.", ""); // for (int i = 1; i < parts.Length; i++) // { // ParametersString += ',' + parts[i].Replace("type parameter.", ""); // } // ParametersString += ">"; // } // this.InterfaceShortName = InterfaceAnnotationHelpers.GetUnqualifiedName(InterfaceName); //} public UnresolvedInterfaceAnnotation(string annotation, Squiggle squiggle, ClousotSuggestion.Kind kind, string parameterstring, string interfacename, string interfacemethod) : base(null, null, annotation, squiggle, kind) { this.ParametersString = parameterstring; this.InterfaceName = interfacename; this.InterfaceMethod = interfacemethod; this.InterfaceShortName = InterfaceAnnotationHelpers.GetUnqualifiedName(interfacename); }
public override void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List <uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { if (kind.StartsWith("Code fix")) { return; } base.Suggestion(type, kind, pc, suggestion, causes, extraInfo); }
public void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List <uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { EnsureMethodStart(); // show suggestion output.Suggestion(type, kind, pc, suggestion, causes, extraInfo); // put it into baseline EmitOutcomeToBaseLine(WarningKind.Informational, ProofOutcome.Bottom, pc, suggestion); }
public override void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List <uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { if (this.skipCurrentMethod) { return; } if (this.options.IncludeSuggestionMessagesInRegression && !this.expectedOutcomes.CheckOutcome(suggestion)) { base.Suggestion(type, kind, pc, suggestion, causes, extraInfo); } }
public void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List <uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { int primaryILOffset, methodILOffset; GetILOffsets(pc, this.currentMethod, out primaryILOffset, out methodILOffset); if (!this.expectedMethodOutcomes.CheckOutcome(WarningKind.Informational, output, this.currentMethod, ProofOutcome.Bottom, suggestion, primaryILOffset, methodILOffset, this.mdDecoder, this.cacheManager)) { // show suggestion output.Suggestion(type, kind, pc, suggestion, causes, extraInfo); // don't count as an error } }
public override void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List <uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { if (this.methodmask != null) { if (this.methodmask.IsMasked(suggestion)) { this.methodmask.SignalMasked(suggestion); return; } } base.Suggestion(type, kind, pc, suggestion, causes, extraInfo); }
public ResolvedInterfaceAnnotation(string filename, string methodname, string annotation, Squiggle squiggle, ClousotSuggestion.Kind kind, UnresolvedInterfaceAnnotation originalAnnotation) : base(filename, methodname, annotation, squiggle, kind) { #region CodeContracts Contract.Requires(methodname != null); Contract.Requires(filename != null); Contract.Requires(kind == ClousotSuggestion.Kind.EnsuresNecessary); #endregion CodeContracts this.OriginalAnnotation = originalAnnotation; }
public BaseAnnotation(string filename, string methodName, string annotation, Squiggle squiggle, ClousotSuggestion.Kind kind) { #region CodeContracts Contract.Requires(annotation != null, "We need an annotation!!!"); Contract.Ensures(this.FileName == filename); Contract.Ensures(this.Annotation == annotation + Constants.String.Signature); Contract.Ensures(this.MethodName == methodName); Contract.Ensures(this.Squiggle == squiggle); Contract.Ensures(this.Kind == kind); #endregion CodeContracts this.Squiggle = squiggle; this.FileName = filename; this.MethodName = methodName; this.Annotation = annotation + Constants.String.Signature; this.Kind = kind; this.statement_syntax = SyntaxFactory.ParseStatement(Annotation); }
public override void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List <uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { if (causes == null) { base.Suggestion(type, kind, pc, suggestion, causes, extraInfo); } else { var suggestionTuple = new Tuple <string, APC, string, ClousotSuggestion.ExtraSuggestionInfo>(kind, pc, suggestion, extraInfo); foreach (var id in causes) { Info info; if (this.DB.TryGetValue(id, out info)) { // Works with side effects info.Add(suggestionTuple); } } } }
public Suggestion AddNewSuggestion(Method method, string suggestion, string kind, ClousotSuggestion.Kind type, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { return(underlying.AddNewSuggestion(method, suggestion, kind, type, extraInfo)); }
public void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List <uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { throw new NotImplementedException(); }
public Precondition(string filename, string methodname, string annotation, Squiggle squiggle, ClousotSuggestion.Kind kind) : base(filename, methodname, annotation, squiggle, kind) { Contract.Requires(filename != null); Contract.Requires(methodname != null); Contract.Requires(squiggle != null); Contract.Requires((kind == ClousotSuggestion.Kind.Requires) || (kind == ClousotSuggestion.Kind.Ensures) || (kind == ClousotSuggestion.Kind.AssumeOnEntry) || (kind == ClousotSuggestion.Kind.AssumeOnCallee) ); }
public Suggestion AddNewSuggestion(Method method, string message, string kind, ClousotSuggestion.Kind type, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { if (!this.IsValid) { return(null); } var res = this.model.NewSuggestion(method); res.Message = message; res.Type = (byte)type; res.Kind = kind; res.ExtraInfo = extraInfo.Serialize(); return(res); }
private bool TrySuggestNecessaryPostconditions(Method method, BoxedExpression exp, out ClousotSuggestion.Kind kind, out string result, out ClousotSuggestion.ExtraSuggestionInfo extraInfo) { result = null; kind = default(ClousotSuggestion.Kind); extraInfo = new ClousotSuggestion.ExtraSuggestionInfo(); var md = this.mdriver.MetaDataDecoder; if (ShouldInferNecessaryPostconditionFor(method) && IsSuitableNecessaryPostcondition(exp)) { #region Interface methods // Is it an interface method? if (md.IsInterface(md.DeclaringType(method))) { kind = ClousotSuggestion.Kind.EnsuresNecessary; this.SetExtraInfo(method, StringConstants.XML.Interface, exp, extraInfo); result = string.Format("The caller expects the postcondition {0} to hold for the interface member {1}. Consider adding such postcondition to enforce all implementations to guarantee it", extraInfo.SuggestedCode, md.Name(method)); return(true); } // Is it an implementation of an interface method? if (md.IsImplicitImplementation(method)) { var implemented = md.ImplementedMethods(method).ToArray(); Contract.Assume(implemented.Length > 0); kind = ClousotSuggestion.Kind.EnsuresNecessary; this.SetExtraInfo(implemented[0], StringConstants.XML.Interface, exp, extraInfo); // we just pick the first one if (implemented.Length == 1) { result = string.Format("The caller expects the postcondition {0} to hold for the interface member {1}. Consider adding the postcondition to enforce all implementations to guarantee it", extraInfo.SuggestedCode, md.Name(method)); } else { extraInfo.CalleeDocumentId = String.Join(" or ", implemented.Select(m => md.DocumentationId(m)).ToArray()); result = string.Format("Add a postcondition {0} to one of the interface members {1}", extraInfo.SuggestedCode, md.Name(method)); } return(true); } #endregion #region Abstract methods if (md.IsAbstract(method)) { kind = ClousotSuggestion.Kind.EnsuresNecessary; this.SetExtraInfo(method, StringConstants.XML.Abstract, exp, extraInfo); result = string.Format("The caller expects the postcondition {0} to hold for the abstract member {1}. Consider adding the postcondition to enforce all overrides to guarantee it", extraInfo.SuggestedCode, md.Name(method)); return(true); } #endregion #region External methods if (md.IsExtern(method)) { kind = ClousotSuggestion.Kind.EnsuresNecessary; this.SetExtraInfo(method, StringConstants.XML.Extern, exp, extraInfo); result = string.Format("The caller expects the postcondition {0} to hold for the external member {1}. Consider adding a postcondition or an assume to document it", extraInfo.SuggestedCode, md.Name(method)); return(true); } #endregion #region Proper methods kind = ClousotSuggestion.Kind.EnsuresNecessary; this.SetExtraInfo(method, StringConstants.XML.ProperMember, exp, extraInfo); result = string.Format("The caller expects the postcondition {0} to hold for the member {1}. Consider adding such postcondition to make sure all implementations satisfy it", extraInfo.SuggestedCode, md.Name(method)); #endregion } return(false); }
public ReadonlyField(string fieldname, string filename, string typename, string methodname, Squiggle squiggle, ClousotSuggestion.Kind kind) : base(filename, methodname, String.Empty, squiggle, kind) { Contract.Requires(typename != null); Contract.Requires(fieldname != null); Contract.Requires(methodname != null); this.TypeName = typename; this.FieldName = fieldname; }
public void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List <uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { }
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 UnresolvedObjectInvariant(string filename, string methodname, string typename, string annotation, Squiggle squiggle, ClousotSuggestion.Kind kind) : base(filename, methodname, annotation, squiggle, kind) { #region CodeContracts Contract.Requires(methodname != null); Contract.Requires(annotation != null); Contract.Requires(typename != null); Contract.Requires(kind == ClousotSuggestion.Kind.ObjectInvariant); Contract.Ensures(typename == this.TypeName); #endregion CodeContracts this.TypeName = typename; }
public void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List <uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { this.WriteLine("{0}: message : Suggested {1}: {2}", pc.PrimarySourceContext(), kind, suggestion); }
internal static bool TryMakeUnresolvedInterfaceAnnotation(CCCheckExtraInfo extrainfo, Squiggle squiggle, ClousotSuggestion.Kind kind, out UnresolvedInterfaceAnnotation annotation) { #region CodeContracts Contract.Requires(extrainfo != null); Contract.Requires(extrainfo.CalleeDocumentId != null); Contract.Requires(extrainfo.TypeDocumentId != null); Contract.Requires(extrainfo.SuggestedCode != null); Contract.Requires(squiggle != null); Contract.Requires(kind == ClousotSuggestion.Kind.EnsuresNecessary); Contract.Ensures(!Contract.Result <bool>() || Contract.ValueAtReturn <UnresolvedInterfaceAnnotation>(out annotation) != null); #endregion CodeContracts annotation = null; var InterfaceMethod = extrainfo.CalleeDocumentId; var InterfaceName = extrainfo.TypeDocumentId; var ParametersString = ""; if (InterfaceName.Contains('<')) { var lastAngle = InterfaceName.LastIndexOf('<'); var beforeAngle = InterfaceName.Remove(lastAngle); var afterAngle = InterfaceName.Replace(beforeAngle, ""); if (string.IsNullOrEmpty(afterAngle)) { RBLogger.Error("Failed to parse interface name {0}", InterfaceName); return(false); } InterfaceName = beforeAngle; var parts = afterAngle.Trim('<', '>').Split(','); ParametersString = "<" + parts[0].Replace("type parameter.", ""); for (int i = 1; i < parts.Length; i++) { ParametersString += ',' + parts[i].Replace("type parameter.", ""); } ParametersString += ">"; } annotation = new UnresolvedInterfaceAnnotation(extrainfo.SuggestedCode, squiggle, kind, ParametersString, InterfaceName, InterfaceMethod); return(true); }
public Suggestion AddNewSuggestion(Method method, string suggestion, string kind, ClousotSuggestion.Kind type, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { Contract.Requires(method != null); Contract.Requires(suggestion != null); Contract.Ensures(Contract.Result <Suggestion>() != null); throw new NotImplementedException(); }