• No results found

A.3 The C# Workspace Statistics Calculator

A.3.2 C# Source Code

A.3.2.1 StatsBuilder.cs

using System.Text;

using RodinFileProcessor.ContextProcessing;

namespace RodinFileProcessor.Output { public static class StatsBuilder {

private static int prefixWidth = 30;

private static int postfix1Width = 3;

private static int postfix2Width = 15;

public static string Print(ContextCollection contextCollection) { StringBuilder sb = new StringBuilder();

foreach (Context context in contextCollection.Contexts) { autoWdProofCount += context.WdAutoProofCount;

int totalWdProofs = autoWdProofCount + interactiveWdProofCount + wdProofCannotBeShownCount;

float autoWdProofPercent = totalWdProofs == 0 ? 0 : autoWdProofCount / (float) totalWdProofs;

sb.AppendFormat(getFixedWidthLine("Auto WD proofs:", autoWdProofCount, autoWdProofPercent))

.AppendLine();

float interactiveWdProofPercent =

totalWdProofs == 0 ? 0 : interactiveWdProofCount / (float)totalWdProofs;

sb.AppendFormat(getFixedWidthLine("Interactive WD proofs:", interactiveWdProofCount, interactiveWdProofPercent)).AppendLine();

float wdCannotBeShownPercent =

totalWdProofs == 0 ? 0 : wdProofCannotBeShownCount / (float)totalWdProofs;

sb.AppendFormat(getFixedWidthLine("WD proof cannot be shown:", wdProofCannotBeShownCount,

wdCannotBeShownPercent)).AppendLine();

sb.AppendFormat(getFixedWidthLine("Total WD proofs:", totalWdProofs)).AppendLine();

sb.AppendLine().AppendLine();

int totalThmProofs = autoThmProofCount + interactiveThmProofCount + thmProofCannotBeShownCount;

float autoThmProofPercent = totalThmProofs == 0 ? 0 : autoThmProofCount / (float) totalThmProofs;

sb.AppendFormat(getFixedWidthLine("Auto THM proofs:", autoThmProofCount, autoThmProofPercent))

.AppendLine();

float interactiveThmProofPercent =

,

interactiveThmProofPercent)).AppendLine();

float thmCannotBeShownPercent =

totalThmProofs == 0 ? 0 : thmProofCannotBeShownCount / (float)totalThmProofs;

sb.AppendFormat(getFixedWidthLine("THM cannot be shown:", thmProofCannotBeShownCount, thmCannotBeShownPercent)).AppendLine();

sb.AppendFormat(getFixedWidthLine("Total THM proofs:", totalThmProofs)).AppendLine();

return sb.ToString();

}

private static string getFixedWidthLine(string prefix, string postfix) {

return prefix.PadRight(prefixWidth, ’ ’) + postfix.PadLeft(postfix1Width, ’ ’);

}

private static string getFixedWidthLine(string prefix, int postfix) { return getFixedWidthLine(prefix, postfix.ToString());

}

private static string getFixedWidthLine(string prefix, int postfix1, float postfix2) { return prefix.PadRight(prefixWidth, ’ ’) + postfix1.ToString().PadLeft(postfix1Width,

’ ’) + public string Name { get; }

public bool WdHasProof { get; set; } public bool WdHasAutoProof { get; set; } public bool WdProofCannotBeShown { get; set; } public bool ThmHasProof { get; set; }

public bool ThmHasAutoProof { get; set; } public bool ThmProofCannotBeShown { get; set; } public virtual bool IsAxiom => true;

public virtual bool IsTheorem => false;

public Axiom(string name) {

private readonly BucProcessor bucFileProcessor;

private readonly BpsProcessor bpsFileProcessor;

private readonly BprProcessor bprFileProcessor;

private List<Axiom> axioms { get; set; }

public string BucFilename => bucFileProcessor.Filename;

public int WdAutoProofCount => axioms.Count(x => x.WdHasAutoProof);

public int ThmAutoProofCount => axioms.Count(x => x.IsTheorem && x.ThmHasAutoProof);

public int WdInteractiveProofCount => axioms.Count(x => x.WdHasProof && !x.

WdHasAutoProof);

public int ThmInteractiveProofCount => axioms.Count(x => x.ThmHasProof && !x.

ThmHasAutoProof);

public int WdProofCannotBeShown => axioms.Count(x => x.WdProofCannotBeShown);

public int ThmProofCannotBeShown => axioms.Count(x => x.ThmProofCannotBeShown);

public int NumAxioms => axioms.Count(x => x.IsAxiom);

public int NumTheorems => axioms.Count(x => x.IsTheorem);

public bool IsValid => bucFileProcessor != null && bucFileProcessor.IsValid;

public Context(string filename) {

foreach (string axiomName in bucFileProcessor.AxiomNames) { Axiom axiom;

A.3.2.4 ContextCollection.cs

public List<Context> Contexts { get; } public ContextCollection(string path) {

if (filesToProcess.Count == 0 && Directory.Exists(path)) {

string[] files = Directory.GetFiles(path, "*.buc", SearchOption.AllDirectories);

filesToProcess = files.ToList();

foreach (string filename in filesToProcess) { var newContext = new Context(filename); public class Theorem : Axiom {

public override bool IsAxiom => false;

public override bool IsTheorem => true;

public Theorem(string name) : base(name) { }

}

}

private const string OrgEventbCorePrproof = "org.eventb.core.prProof";

private const string OrgEventbCoreConfidence = "org.eventb.core.confidence";

private const string OrgEventbCorePrrule = "org.eventb.core.prRule";

private const string OrgEventbCorePrante = "org.eventb.core.prAnte";

// key: axm name, value: true if proof is not complete, i.e. not shown private readonly List<string> proofCannotBeShown = new List<string>();

public BprProcessor(string filename) {

foreach (XElement el in xdoc.Root.Elements(OrgEventbCorePrproof)) { string name = el.Attribute("name").Value;

public bool GetProofCannotBeShown(string axiomName, string proofType) { if (proofCannotBeShown.Contains(axiomName + "/" + proofType)) {

return true;

}

return false;

}

private void recurseProof(XElement proofBranch, string proofName, int confidence) { if (proofBranch != null) {

confidence = Math.Min(

confidence,

Convert.ToInt32(proofBranch.Attribute(OrgEventbCoreConfidence).Value));

}

if (proofBranch == null || confidence == 0) { // no rule info, "Cannot be shown" case

}

var children = proofBranch.Elements(OrgEventbCorePrante);

foreach (XElement rule in children) {

recurseProof(rule.Element(OrgEventbCorePrrule), proofName, confidence);

private const string orgEventbCorePsstatus = "org.eventb.core.psStatus";

private const string orgEventbCorePsmanual = "org.eventb.core.psManual";

private Dictionary<string, bool> IsAutoProof { get; } public BpsProcessor(string filename) {

foreach (XElement el in xdoc.Root.Elements(orgEventbCorePsstatus)) { string name = el.Attribute("name").Value;

bool autoProved = el.Attribute(orgEventbCorePsmanual).Value == "false";

IsAutoProof.Add(name, autoProved);

private bool hasProof(string axmName, string proofType) { foreach (string proofName in IsAutoProof.Keys) {

if (proofName == axmName + "/" + proofType) { return true;

} }

return false;

}

private bool hasAutoProof(string axmName, string proofType) { foreach (string proofName in IsAutoProof.Keys) {

if (proofName == axmName + "/" + proofType) { return IsAutoProof[proofName];

private const string FileExtension = "buc";

private const string OrgEventbCoreAxiom = "org.eventb.core.axiom";

private const string OrgEventbCoreLabel = "org.eventb.core.label";

private const string OrgEventbCoreTheorem = "org.eventb.core.theorem";

public string Filename { get; } public bool IsValid { get; } public string ContextName { get; } public List<string> AxiomNames { get; }

public Dictionary<string, bool> IsTheorem { get; } // otherwise Axiom public BucProcessor(string filename) {

foreach (XElement el in xdoc.Root.Elements(OrgEventbCoreAxiom)) { string name = el.Attribute(OrgEventbCoreLabel).Value;

AxiomNames.Add(name);

// axiom or theorem

bool isTheorem = el.Attribute(OrgEventbCoreTheorem) != null

&&

el.Attribute(OrgEventbCoreTheorem).Value == "true";

}

var menuOptionStr = readMenuOption(out var exitApp);

if (exitApp) break;

processMenuOption(menuOptionStr);

} while (true);

}

private static string readMenuOption(out bool exitApp) { printMenu();

.AppendLine("*** (1) Set Worksapce Path ***") .AppendLine("*** ***")

.AppendLine("*** (2) Print Workspace Stats ***") .AppendLine("*** ***")

private static void processMenuOption(string menuOptionStr) { int menuOption;

try {

menuOption = Convert.ToInt32(menuOptionStr);

private static void printMessage(string message) { Console.Write("*** ");

var returnVal = Console.ReadLine() ?? "";

Console.WriteLine();

return returnVal;

}

private static void processWorkspacePath() {

printMessage("Please enter the path to the workspace:");

var oldValue = workspaceDirectory;

workspaceDirectory = readUserInput();

if (!Directory.Exists(workspaceDirectory)) {

printMessage("Invalid path: path does not exist");

workspaceDirectory = oldValue;

printMessage("The path you have specified contains no Rodin files to analyze.");

return;

Appendix B

Rodin Screen Shots

An in-depth discussion of the Rodin tool suite was presented in Chapter 6, but the focus was on the Event-B modelling language as well as Rodin’s inference mechanism. In this appendix, we include a number of screen shots of Rodin’s user interface. For a detailed discussion of Rodin’s user interface, see (Jastram 2012).

B.1 The Rodin User Interfaces

The current section includes two examples of typical user interface screens one would see when creating and editing contexts, and discharging proof obligations.

Figure B.1 shows the Event-B context editor and is part of Rodin’s modelling UI. This interface can be used to create and edit Rodin contexts. The most significant functions of the interface are the ‘+’ signs next to the following headings:

• EXTENDS: Allows the user to select another context in the same project that will be extended in the current context;

• SETS: Allows the user to introduce an additional carrier set (see Section 6.4.1);

• CONSTANTS: Allows the user to introduce a global symbol (constant) that is within the scope of all the axioms and theorems in the AXIOMS section, as well as in the scope of all derived contexts’ axioms;

and

• AXIOMS: Allows the user to add axioms and theorems to the context.

Output from the static checker (see Section 6.5.1) is added to the Rodin Problems tab and clicking on a symbol on the Symbols tab will inject the selected symbol in the selected input control.

Finally, the Event-B explorer on the left provides various options to create and manipulate Event-B projects (see Appendix A.1) and contexts.

Figure B.1: The Modelling User Interface

155

Figure B.2 is part of Rodin’s proving UI. This part of the user interface can be used to inspect and manipulate proof trees, and discharge proof obligations interactively.

The screen is divided into five sections, namely

• The Proof Tree: The user can use this control to inspect the proof tree or to manipulate the proof tree. For example, a typical action is to prune the proof tree at the selected proof tree node to attempt a different interactive strategy to discharge a proof obligation;

• The Selected Hypotheses: This control lists the hypotheses for the proof tree node that is selected in the Proof Treecontrol. Text in red indicates the availability of a rewrite rule that can be applied. Note that the list of hypotheses can be empty;

• The Goal: This control displays the goal for the proof tree node that is selected in the Proof Tree control;

• The Proof Control: The user can use this control to invoke a specific theorem prover, apply the default auto tactic profile, apply the default post tactic profile or apply lasso. The selected action is always performed for the proof tree node that is selected in the Proof Tree control; and

• The Event-B Explorer: This control provides various options to create and manipulate Event-B projects (see Appendix A.1) and contexts.

Figure B.2: The Proving User Interface

157

B.2 Rodin Auto-tactic Profiles

This section includes screen shots of the Default Auto/Post Tactic Profile selector and the tactic profile editor.

Tactic profiles are discussed in Section 6.11.

Figure B.3 shows the user interface for selecting an auto tactic profile as well as options for enabling and disabling auto tactic profiles.

Figure B.4 shows the user interface for creating a custom tactic profile. Once created, the profile name can be selected from the list of available tactic profiles in Figure B.3.

Figure B.3: The Auto/Post Tactic Selector

159

Figure B.4: The Tactic Profile Editor

160

Appendix C

Rodin Contexts