예제 #1
0
        private static void addLinebreaks(PrintRule rule, InfoPanelContent content,
                                          Stack <Color> indents, List <int> breakIndices)
        {
            var indentColors = indents.ToList();

            indentColors.Reverse();
            var offset    = 0;
            var oldLength = content.Length;

            for (var i = 0; i < breakIndices.Count; i++)
            {
                if (rule.indent && i == breakIndices.Count - 1)
                {
                    indents.Pop();
                    indentColors.RemoveAt(indentColors.Count - 1);
                }

                // add the actual linebreak
                content.Insert(breakIndices[i] + offset, "\n");
                offset   += content.Length - oldLength;
                oldLength = content.Length;

                // add the indents
                foreach (var color in indentColors)
                {
                    content.Insert(breakIndices[i] + offset, color == Color.Transparent ? " " : PrintConstants.indentDiff, PrintConstants.DefaultFont, color);
                    offset   += content.Length - oldLength;
                    oldLength = content.Length;
                }
            }
        }
예제 #2
0
 public override void InfoPanelText(InfoPanelContent content, PrettyPrintFormat format)
 {
     foreach (Literal l in Literals)
     {
         content.Append(l + "\n");
     }
 }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Point click = ((MouseEventArgs)e).Location;

            if ((click.Y >= 0) && (click.Y < ImageHeight) &&
                (click.X >= 0) && (click.X < ImageWidth))
            {
                int index = click.Y * ImageWidth + click.X;

                if (index < quantifiers.Count)
                {
                    Quantifier q          = quantifiers[index];
                    int        colorIndex = quantifierColorSorting.IndexOf(q);
                    if ((colorIndex >= 0) && (colorIndex < colors.Count))
                    {
                        this.colorBox.BackColor = colors[colorIndex];
                        var content = new InfoPanelContent();
                        q.InfoPanelText(content, new PrettyPrintFormat {
                            printRuleDict = new PrintRuleDictionary()
                        });
                        content.finalize();
                        this.boogieQuantifierText.Text = content.ToString();

                        this.quantifierLinkedText.Text = q.ToString();
                    }
                    else
                    {
                        this.colorBox.BackColor        = Color.White;
                        this.boogieQuantifierText.Text = "";
                        this.quantifierLinkedText.Text = "";
                    }
                }
            }
        }
예제 #4
0
 private static bool linebreaksNecessary(InfoPanelContent content, PrettyPrintFormat format, bool isMultiline, int startLength)
 {
     if (format.maxWidth == 0)
     {
         return(false);
     }
     return(isMultiline || (content.Length - startLength > format.maxWidth));
 }
예제 #5
0
 public override void SummaryInfo(InfoPanelContent content)
 {
     content.switchFormat(PrintConstants.SubtitleFont, PrintConstants.sectionTitleColor);
     content.Append("Term Info:\n");
     content.switchToDefaultFormat();
     content.Append("\nIdentifier: " + id).Append('\n');
     content.Append("Number of Children: " + Args.Length).Append('\n');
 }
예제 #6
0
        public void PrettyPrint(InfoPanelContent content, PrettyPrintFormat format, int eqNumber = -1)
        {
            var numberingString = eqNumber == -1 ? "" : $"({eqNumber}) ";

            content.switchToDefaultFormat();
            content.Append(numberingString);
            source.PrettyPrint(content, format, numberingString.Length);
            EqualityExplanationPrinter.singleton.visit(this, Tuple.Create(content, format, false, numberingString.Length));
        }
예제 #7
0
 public override void SummaryInfo(InfoPanelContent content)
 {
     content.switchFormat(PrintConstants.TitleFont, PrintConstants.instantiationTitleColor);
     content.Append("Quantifier Info:\n");
     content.switchToDefaultFormat();
     content.Append("\nPrint name: ").Append(PrintName).Append('\n');
     content.Append("QId: ").Append(Qid).Append('\n');
     content.Append("Number of Instantiations: " + Instances.Count).Append('\n');
     content.Append("Cost: " + Cost).Append('\n');
     content.Append("Number of Conflicts: " + GeneratedConflicts).Append("\n\n");
 }
예제 #8
0
 public override void InfoPanelText(InfoPanelContent content, PrettyPrintFormat format)
 {
     if (Conflict != null)
     {
         Conflict.InfoPanelText(content, format);
     }
     else
     {
         content.Append("No conflict");
     }
 }
예제 #9
0
        private void addPrefix(PrintRule rule, InfoPanelContent content, ICollection <int> breakIndices)
        {
            var prefix = rule.prefix(isPrime);

            content.Append(prefix);
            if (!string.IsNullOrWhiteSpace(prefix) &&
                rule.prefixLineBreak == PrintRule.LineBreakSetting.After)
            {
                breakIndices.Add(content.Length);
            }
        }
예제 #10
0
        public override void SummaryInfo(InfoPanelContent content)
        {
            content.switchFormat(PrintConstants.TitleFont, PrintConstants.instantiationTitleColor);
            content.Append("Instantiation ").Append('@').Append(LineNo + ":\n");
            content.switchToDefaultFormat();

            content.Append('\n').Append(Quant.PrintName).Append('\n');
            content.Append("Depth: " + depth).Append('\n');
            content.Append($"Longest Subpath Length: {DeepestSubpathDepth.ToString("F")}\n");
            content.Append("Cost: ").Append(Cost.ToString("F")).Append("\n\n");
        }
예제 #11
0
        private void addSuffix(PrintRule rule, InfoPanelContent content, ICollection <int> breakIndices)
        {
            var suffix = rule.suffix(isPrime);

            content.switchFormat(rule.font ?? PrintConstants.DefaultFont, rule.color);
            if (!string.IsNullOrWhiteSpace(suffix) &&
                rule.suffixLineBreak == PrintRule.LineBreakSetting.Before)
            {
                breakIndices.Add(content.Length);
            }
            content.Append(suffix);
        }
예제 #12
0
        public void PrettyPrint(InfoPanelContent content, PrettyPrintFormat format, int indent = 0)
        {
            var indentColors = Enumerable.Empty <Color>();

            if (indent >= 2)
            {
                indentColors = indentColors.Concat(Enumerable.Repeat(PrintConstants.defaultTextColor, 1));
                indentColors = indentColors.Concat(Enumerable.Repeat(Color.Transparent, indent - 2));
            }
            indentColors = indentColors.Concat(Enumerable.Repeat(PrintConstants.defaultTextColor, format.CurrentEqualityExplanationPrintingDepth));

            PrettyPrint(content, new Stack <Color>(indentColors), format);
        }
예제 #13
0
 private void addInfix(PrintRule rule, InfoPanelContent content, ICollection <int> breakIndices)
 {
     content.switchFormat(PrintConstants.DefaultFont, rule.color);
     if (rule.infixLineBreak == PrintRule.LineBreakSetting.Before)
     {
         breakIndices.Add(content.Length);
     }
     content.Append(rule.infix(isPrime));
     if (rule.infixLineBreak == PrintRule.LineBreakSetting.After)
     {
         breakIndices.Add(content.Length);
     }
 }
예제 #14
0
 public void printName(InfoPanelContent content, PrettyPrintFormat format)
 {
     content.Append(Name);
     if (format.showType)
     {
         content.Append(GenericType);
     }
     if (iterationOffset > 0)
     {
         content.Append("_-" + iterationOffset);
     }
     if (format.showTermId)
     {
         content.Append("[" + (id >= 0 ? id.ToString() : "g" + -id) + (isPrime ? "'" : "") + "]");
     }
 }
예제 #15
0
        /// <summary>
        /// Prints a section explaining the equality substitutions necessary to obtain a term matching the trigger.
        /// </summary>
        public void PrintEqualitySubstitution(InfoPanelContent content, PrettyPrintFormat format)
        {
            content.switchFormat(PrintConstants.SubtitleFont, PrintConstants.sectionTitleColor);
            content.Append("\nSubstituting equalities yields:\n\n");
            content.switchToDefaultFormat();

            foreach (var blamedTerm in BlamedEffectiveTerms)
            {
                blamedTerm.highlightTemporarily(format, PrintConstants.blameColor);
            }

            foreach (var boundTerm in BoundEffectiveTerms)
            {
                boundTerm.highlightTemporarily(format, PrintConstants.bindColor);
            }

            foreach (var pair in EffectiveBlameTerms.Zip(fullPattern.Args, Tuple.Create))
            {
                var effectiveTerm       = pair.Item1;
                var usedPattern         = pair.Item2;
                var rootTerm            = equalities.FirstOrDefault(eq => eq.Key == usedPattern).Value?.FirstOrDefault(eqSource => TopLevelTerms.Contains(eqSource.Item2))?.Item2 ?? effectiveTerm;
                var topLevelTermNumber  = format.termNumbers.First(kv => kv.Key.isSubterm(rootTerm.id));
                var usedEqualityNumbers = equalities.Keys.Where(k => usedPattern.isSubterm(k)).Select(k => bindings[k])
                                          .Select(b => {
#if !DEBUG
                    try
                    {
#endif
                    return(format.equalityNumbers.First(kv => Term.semanticTermComparer.Equals(kv.Key.target, b.Item2)).Value);

#if !DEBUG
                }
                                                  catch (Exception)
                {
                    return(0);
                }
#endif
                }).Distinct();
                content.Append($"Substituting ({String.Join("), (", usedEqualityNumbers)}) in ({topLevelTermNumber.Value}):\n");
                effectiveTerm.PrettyPrint(content, format);
                content.Append("\n\n");
                content.switchToDefaultFormat();
            }
        }
예제 #16
0
        /// <summary>
        /// Displays a printable.
        /// </summary>
        /// <param name="c"> The printable to be displayed. </param>
        /// <ramarks> Calls to this method are synchronized, i.e. it will finish displaying one printable before displaying the next. </remarks>
        public void UpdateSync(IPrintable c)
        {
            // We have an additional UI update
            Interlocked.Increment(ref workCounter);

            //Must run on the main (UI) thread
            if (InvokeRequired)
            {
                Invoke((MethodInvoker) delegate { uiUpdateTimer.Start(); });
            }
            else
            {
                uiUpdateTimer.Start();
            }

            lock (this)
            {
                // During debugging we want VS to catch exceptions so we can inspect the program state at the point where the exception was thrown.
                // For release builds we catch the execption here and display a message so the user knows that that they shouldn't wait for the generalization.
#if !DEBUG
                try
                {
#endif
                DisplayMessage("busy...");

                // Update
                var content = new InfoPanelContent();
                c.InfoPanelText(content, getFormatFromGUI());
                content.finalize();
                currentInfoPanelPrintable = c;
                infoPanelQueue.Enqueue(content);
#if !DEBUG
            }
            catch (Exception e)
            {
                // Notify user
                Interlocked.Decrement(ref workCounter);
                DisplayMessage($"An exception was thrown. Please report this bug to [email protected].\nDescription of the exception: {e.Message}");
                Console.WriteLine(e);
            }
#endif
            }
        }
예제 #17
0
        public override string ToString()
        {
            string t;
            bool   isBin = Term.Args.Length == 2;

            if (Negated && Term.Name == "or")
            {
                Negated = false;
                Term    = new Term("And", LogProcessor.NegateAll(Term.Args));
            }

            if (isBin)
            {
                if (Term.Name.Any(char.IsLetterOrDigit))
                {
                    isBin = false;
                }
            }

            if (Term == null)
            {
                t = "(nil)";
            }
            else if (isBin)
            {
                var content0 = new InfoPanelContent();
                var content1 = new InfoPanelContent();
                Term.Args[0].PrettyPrint(content0, PrettyPrintFormat.DefaultPrettyPrintFormat());
                Term.Args[1].PrettyPrint(content1, PrettyPrintFormat.DefaultPrettyPrintFormat());
                content0.finalize();
                content1.finalize();
                t = $"{content0}  {Term.Name}  {content1}";
            }
            else
            {
                var content = new InfoPanelContent();
                Term.PrettyPrint(content, PrettyPrintFormat.DefaultPrettyPrintFormat());
                content.finalize();
                t = content.ToString();
            }
            return(string.Format("{0}p{1}  {3}{2}", Negated ? "~" : "", Id, t, Implied == null ? "" : "[+" + Implied.Length + "] "));
        }
예제 #18
0
        /// <summary>
        /// Prints a message in the left panel.
        /// </summary>
        /// <param name="message"> The message to be displayed </param>
        public void DisplayMessage(string message)
        {
            // We have an additional UI update
            Interlocked.Increment(ref workCounter);

            // Must run on the main (UI) thread
            if (InvokeRequired)
            {
                Invoke((MethodInvoker) delegate { uiUpdateTimer.Start(); });
            }
            else
            {
                uiUpdateTimer.Start();
            }

            // Enqueue the message
            var messageContent = new InfoPanelContent();

            messageContent.Append(message);
            messageContent.finalize();
            infoPanelQueue.Enqueue(messageContent);
        }
예제 #19
0
 public virtual void SummaryInfo(InfoPanelContent content)
 {
     content.Append("No summary available.");
 }
예제 #20
0
        public override void InfoPanelText(InfoPanelContent content, PrettyPrintFormat format)
        {
            SummaryInfo(content);
            content.Append("Highlighted terms are ");
            if (bindingInfo.IsPatternMatch())
            {
                content.switchFormat(PrintConstants.DefaultFont, PrintConstants.patternMatchColor);
                content.Append("matched");
                content.switchToDefaultFormat();
                content.Append(" or ");
                content.switchFormat(PrintConstants.DefaultFont, PrintConstants.equalityColor);
                content.Append(PrintConstants.LargeTextMode ? "matched using\nequality" : "matched using equality");
                content.switchToDefaultFormat();
                content.Append(" or ");
            }
            content.switchFormat(PrintConstants.DefaultFont, PrintConstants.blameColor);
            content.Append("blamed");
            content.switchToDefaultFormat();
            content.Append(" or ");
            content.switchFormat(PrintConstants.DefaultFont, PrintConstants.bindColor);
            content.Append("bound");
            content.switchToDefaultFormat();
            content.Append(".\n\n");

            tempHighlightBlameBindTerms(format);

            if (!bindingInfo.IsPatternMatch())
            {
                content.switchFormat(PrintConstants.BoldFont, PrintConstants.instantiationTitleColor);
                if (InstantiationMethod == "theory-solving")
                {
                    content.Append($"Instantiated by the {Quant.Namespace} theory solver.\n\n");
                }
                else
                {
                    content.Append($"Instantiated using {InstantiationMethod}.\n\n");
                }
                content.switchToDefaultFormat();

                if (bindingInfo.explicitlyBlamedTerms.Any())
                {
                    content.switchFormat(PrintConstants.SubtitleFont, PrintConstants.sectionTitleColor);
                    content.Append("Blamed Terms:\n");
                    content.switchToDefaultFormat();
                }

                var termNumbering = 1;

                foreach (var t in bindingInfo.explicitlyBlamedTerms)
                {
                    if (!format.termNumbers.TryGetValue(t, out var termNumber))
                    {
                        termNumber = termNumbering;
                        ++termNumbering;
                        format.termNumbers[t] = termNumber;
                    }
                    var numberingString = $"({termNumber}) ";
                    content.Append($"\n{numberingString}");
                    t.PrettyPrint(content, format, numberingString.Length);
                    content.switchToDefaultFormat();
                    content.Append("\n\n");
                }
            }

            if (bindingInfo.IsPatternMatch())
            {
                content.switchFormat(PrintConstants.SubtitleFont, PrintConstants.sectionTitleColor);
                content.Append("Blamed Terms:\n\n");
                content.switchToDefaultFormat();

                var termNumbering = 1;

                var blameTerms         = bindingInfo.getDistinctBlameTerms();
                var distinctBlameTerms = blameTerms.Where(req => bindingInfo.TopLevelTerms.Contains(req) ||
                                                          (!bindingInfo.equalities.SelectMany(eq => eq.Value).Any(t => t.Item2.id == req.id) &&
                                                           !bindingInfo.equalities.Keys.Any(k => bindingInfo.bindings[k].Item2 == req)));

                foreach (var t in distinctBlameTerms)
                {
                    if (!format.termNumbers.TryGetValue(t, out var termNumber))
                    {
                        termNumber = termNumbering;
                        ++termNumbering;
                        format.termNumbers[t] = termNumber;
                    }
                    var numberingString = $"({termNumber}) ";
                    content.Append($"\n{numberingString}");
                    t.PrettyPrint(content, format, numberingString.Length);
                    content.switchToDefaultFormat();
                    content.Append("\n\n");
                }

                if (bindingInfo.equalities.Count > 0)
                {
                    var numberOfTopLevelTerms = bindingInfo.getDistinctBlameTerms().Count;

                    content.switchFormat(PrintConstants.SubtitleFont, PrintConstants.sectionTitleColor);
                    content.Append("\nRelevant equalities:\n\n");
                    content.switchToDefaultFormat();

                    format.printContextSensitive = false;
                    foreach (var equality in bindingInfo.equalities)
                    {
                        var effectiveTerm = bindingInfo.bindings[equality.Key].Item2;
                        foreach (var term in equality.Value.Select(t => t.Item2).Distinct(Term.semanticTermComparer))
                        {
                            EqualityExplanation explanation;
#if !DEBUG
                            try
                            {
#endif
                            explanation = bindingInfo.EqualityExplanations.First(ee => ee.source.id == term.id && ee.target.id == effectiveTerm.id);
#if !DEBUG
                        }
                        catch (Exception)
                        {
                            explanation = new TransitiveEqualityExplanation(term, effectiveTerm, new EqualityExplanation[0]);
                        }
#endif
                            if (!format.equalityNumbers.TryGetValue(explanation, out var termNumber))
                            {
                                termNumber = termNumbering;
                                ++termNumbering;
                                format.equalityNumbers[explanation] = termNumber;
                            }

                            if (format.ShowEqualityExplanations)
                            {
                                explanation.PrettyPrint(content, format, termNumber);
                            }
                            else
                            {
                                var numberingString = $"({termNumber}) ";
                                content.switchToDefaultFormat();
                                content.Append(numberingString);
                                var indentString = $"¦{String.Join("", Enumerable.Repeat(" ", numberingString.Length - 1))}";
                                term.PrettyPrint(content, format, numberingString.Length);
                                content.switchToDefaultFormat();
                                content.Append($"\n{indentString}= (explanation omitted)\n{indentString}");
                                effectiveTerm.PrettyPrint(content, format, numberingString.Length);
                            }
                            content.Append("\n\n");
                        }
                    }
                    format.printContextSensitive = true;

                    bindingInfo.PrintEqualitySubstitution(content, format);
                }
            }

            if (Bindings.Any())
            {
                content.switchFormat(PrintConstants.SubtitleFont, PrintConstants.sectionTitleColor);
                content.Append("Binding information:");
                content.switchToDefaultFormat();

                foreach (var bindings in bindingInfo.getBindingsToFreeVars())
                {
                    content.Append("\n\n");
                    content.Append(bindings.Key.PrettyName).Append(" was bound to:\n");
                    bindings.Value.PrettyPrint(content, format);
                    content.switchToDefaultFormat();
                }
            }

            if (Quant.BodyTerm != null)
            {
                content.switchFormat(PrintConstants.SubtitleFont, PrintConstants.sectionTitleColor);
                content.Append("\n\n\nThe quantifier body:\n\n");
                content.switchToDefaultFormat();
                Quant.BodyTerm.PrettyPrint(content, format);
                content.Append("\n\n");
            }
            format.restoreAllOriginalRules();

            content.switchToDefaultFormat();
            content.switchFormat(PrintConstants.SubtitleFont, PrintConstants.sectionTitleColor);
            content.Append("The resulting term:\n\n");
            content.switchToDefaultFormat();
            concreteBody.PrettyPrint(content, format);

            format.restoreAllOriginalRules();
        }
예제 #21
0
 public void printNoMatchdisclaimer(InfoPanelContent content)
 {
     content.switchFormat(PrintConstants.ItalicFont, PrintConstants.warningTextColor);
     content.Append("No pattern match found. Possible reasons include (hidden) equalities\nand / or automatic term simplification.\n");
     content.switchToDefaultFormat();
 }
예제 #22
0
 public virtual void InfoPanelText(InfoPanelContent content, PrettyPrintFormat format)
 {
 }
예제 #23
0
 public override void InfoPanelText(InfoPanelContent content, PrettyPrintFormat format)
 {
     SummaryInfo(content);
     BodyTerm.PrettyPrint(content, format);
 }
예제 #24
0
 public override void InfoPanelText(InfoPanelContent content, PrettyPrintFormat format)
 {
     SummaryInfo(content);
     content.Append('\n');
     PrettyPrint(content, new Stack <Color>(), format);
 }
예제 #25
0
        private bool PrettyPrint(InfoPanelContent content, Stack <Color> indentFormats, PrettyPrintFormat format)
        {
            var printRule        = format.getPrintRule(this);
            var parentRule       = format.GetParentPrintRule();
            var isMultiline      = false;
            var breakIndices     = new List <int>();
            var startLength      = content.Length;
            var needsParenthesis = this.needsParenthesis(format, printRule, parentRule);

            content.switchFormat(printRule.font ?? PrintConstants.DefaultFont, printRule.color);

            // check for cutoff
            if (format.MaxTermPrintingDepth == 1)
            {
                if (ContainsGeneralization())
                {
                    content.switchFormat(printRule.font ?? PrintConstants.DefaultFont, PrintConstants.generalizationColor);
                    content.Append(">...<");
                }
                else
                {
                    content.Append("...");
                }
                return(false);
            }

            if (printRule.indent)
            {
                indentFormats.Push(printRule.color);
            }
            if (needsParenthesis)
            {
                content.Append('(');
            }
            addPrefix(printRule, content, breakIndices);

            if (printChildren(format, printRule))
            {
                for (var i = 0; i < Args.Length; i++)
                {
                    var t = Args[i];

                    // Note: DO NOT CHANGE ORDER (-> short circuit)
                    isMultiline = t.PrettyPrint(content, indentFormats, format.NextTermPrintingDepth(this, i)) ||
                                  isMultiline;

                    if (i < Args.Length - 1)
                    {
                        addInfix(printRule, content, breakIndices);
                    }
                }
            }

            addSuffix(printRule, content, breakIndices);
            if (needsParenthesis)
            {
                content.Append(')');
            }

            // are there any lines to break?
            var lineBreaks = linebreaksNecessary(content, format, isMultiline && (breakIndices.Count > 0), startLength);

            if (lineBreaks)
            {
                addLinebreaks(printRule, content, indentFormats, breakIndices);
            }
            else if (printRule.indent)
            {
                // just remove indent if necessary
                indentFormats.Pop();
            }

            return(lineBreaks);
        }
예제 #26
0
 public override void InfoPanelText(InfoPanelContent content, PrettyPrintFormat format)
 {
     Fwd.InfoPanelText(content, format);
 }