private void CommitOne(QuantifierWithTriggers q, bool addHeader) { var errorLevel = ErrorLevel.Info; var msg = new StringBuilder(); var indent = addHeader ? " " : ""; bool suppressWarnings = Attributes.Contains(q.quantifier.Attributes, "nowarn"); if (!TriggerUtils.NeedsAutoTriggers(q.quantifier)) // NOTE: split and autotriggers attributes are passed down to Boogie { var extraMsg = TriggerUtils.WantsAutoTriggers(q.quantifier) ? "" : " Note that {:autotriggers false} can cause instabilities. Consider using {:nowarn}, {:matchingloop} (not great either), or a manual trigger instead."; msg.AppendFormat("Not generating triggers for \"{0}\".{1}", Printer.ExprToString(q.quantifier.Term), extraMsg).AppendLine(); } else { if (addHeader) { msg.AppendFormat("For expression \"{0}\":", Printer.ExprToString(q.quantifier.Term)).AppendLine(); } foreach (var candidate in q.Candidates) { q.quantifier.Attributes = new Attributes("trigger", candidate.Terms.Select(t => t.Expr).ToList(), q.quantifier.Attributes); } AddTriggersToMessage("Selected triggers:", q.Candidates, msg, indent); AddTriggersToMessage("Rejected triggers:", q.RejectedCandidates, msg, indent, true); #if QUANTIFIER_WARNINGS var WARN_TAG = DafnyOptions.O.UnicodeOutput ? "⚠ " : "/!\\ "; var WARN_TAG_OVERRIDE = suppressWarnings ? "(Suppressed warning) " : WARN_TAG; var WARN_LEVEL = suppressWarnings ? ErrorLevel.Info : ErrorLevel.Warning; var WARN = indent + WARN_TAG_OVERRIDE; if (!q.CandidateTerms.Any()) { errorLevel = WARN_LEVEL; msg.Append(WARN).AppendLine("No terms found to trigger on."); } else if (!q.Candidates.Any()) { errorLevel = WARN_LEVEL; msg.Append(WARN).AppendLine("No trigger covering all quantified variables found."); } else if (!q.CouldSuppressLoops && !q.AllowsLoops) { errorLevel = WARN_LEVEL; msg.Append(WARN).AppendLine("Suppressing loops would leave this expression without triggers."); } else if (suppressWarnings) { errorLevel = ErrorLevel.Warning; msg.Append(indent).Append(WARN_TAG).AppendLine("There is no warning here to suppress."); } #endif } if (msg.Length > 0) { var msgStr = msg.ToString().TrimEnd("\r\n ".ToCharArray()); reporter.Message(MessageSource.Rewriter, errorLevel, q.quantifier.tok, msgStr); } }
public override bool Message(MessageSource source, ErrorLevel level, IToken tok, string msg) { base.Message(source, level, tok, msg); return(WrappedReporter.Message(source, level, tok, msgPrefix + msg)); }