public void GenerateMethod()
        {
            string method = "";

            method += "method MM1(q: seq<int>) returns(i: nat, q0: seq<int>, min: int, max: int)\n";
            method += indentation + "requires 0 < |q|\n";
            method += indentation + "ensures Inv(q, i, min, max)\n";
            method += indentation + "ensures i == |q|\n";


            assertiveToolDS ds = new assertiveToolDS();

            ds.Name = "MinAndMax";
            ds.AddArgument(new Variable("q", "seq<int>"));
            ds.AddLoclVar(new Variable("i", "nat"));
            ds.AddLoclVar(new Variable("q0", "seq<int>"));
            ds.AddRetValue(new Variable("min", "int"));
            ds.AddRetValue(new Variable("max", "int"));
            ds.AddPreCond("0 < |q|");
            ds.AddPostCond("MinElement(min, q)");
            ds.AddPostCond("MaxElement(max, q)");
            ds.strengthenPostCond("Inv(q, i, min, max)");
            ds.strengthenPostCond("i == |q|");

            string name;

            name = "MM1";
            ds.NewMethod.Name = name;

            Assert.AreEqual(method, ds.generateMethod());
        }
        public void GenerateLemma()
        {
            string lemma = "";

            lemma += "lemma L1(q: seq<int>, i: nat, q0: seq<int>, min: int, max: int)\n";
            lemma += indentation + "requires Inv(q, i, min, max)\n";
            lemma += indentation + "requires i == |q|\n";
            lemma += indentation + "ensures MinElement(min, q)\n";
            lemma += indentation + "ensures MaxElement(max, q)\n";


            assertiveToolDS ds = new assertiveToolDS();

            ds.Name = "MinAndMax";
            ds.AddArgument(new Variable("q", "seq<int>"));
            ds.AddLoclVar(new Variable("i", "nat"));
            ds.AddLoclVar(new Variable("q0", "seq<int>"));
            ds.AddRetValue(new Variable("min", "int"));
            ds.AddRetValue(new Variable("max", "int"));
            ds.AddPreCond("0 < |q|");
            ds.AddPostCond("MinElement(min, q)");
            ds.AddPostCond("MaxElement(max, q)");
            ds.strengthenPostCond("Inv(q, i, min, max)");
            ds.strengthenPostCond("i == |q|");

            string name;

            name = "L1";
            ds.StrengthLemma.Name = name;

            Assert.AreEqual(lemma, ds.generateStrengthLemma());
        }
        public static assertiveToolDS initDs5()
        {
            assertiveToolDS ds = new assertiveToolDS();

            ds.Name = "MM2'";

            ds.AddArgument(new Variable("q", "seq<int>"));
            ds.AddArgument(new Variable("i0", "nat"));
            ds.AddArgument(new Variable("min0", "int"));
            ds.AddArgument(new Variable("max0", "int"));
            ds.AddRetValue(new Variable("i", "nat"));
            ds.AddRetValue(new Variable("min", "int"));
            ds.AddRetValue(new Variable("max", "int"));
            ds.AddPreCond("0 < |q| && min0 == q[0] && max0 == q[0] && i0 == 1");
            ds.AddPostCond("Inv(q, i, min, max) && i == |q|");
            ds.weakenPreCond("Inv(q, i, min, max)");


            string name;

            name = "MM3";
            ds.NewMethod.Name = name;

            name = "L3";
            ds.WeakLemma.Name = name;

            name = "L2";
            ds.StrengthLemma.Name = name;


            return(ds);
        }
        public static assertiveToolDS initDs4()
        {
            assertiveToolDS ds = new assertiveToolDS();

            ds.Name = "MinAndMax";
            ds.AddArgument(new Variable("q", "seq<int>"));
            ds.AddLoclVar(new Variable("i", "nat"));
            ds.AddLoclVar(new Variable("q'", "seq<int>"));
            ds.AddLoclVar(new Variable("j'", "int"));
            ds.AddLoclVar(new Variable("k'", "nat"));
            ds.AddRetValue(new Variable("min", "int"));
            ds.AddRetValue(new Variable("max", "int"));
            ds.AddPreCond("0 < |q|");
            ds.AddPostCond("MinElement(min, q)");
            ds.AddPostCond("MaxElement(max, q)");
            ds.strengthenPostCond("Inv(q, i, min, max)");
            ds.strengthenPostCond("Inv(q, i, min, max)");

            string name;

            name = "MM1";
            ds.NewMethod.Name = name;

            name = "L1";
            ds.StrengthLemma.Name = name;


            return(ds);
        }
        public void IdenticalValues()
        {
            string body = "";

            body += indentation + "var i : nat;\n";
            body += indentation + "assert 0 < |q|;\n";
            body += indentation + "i, min, max := MM1(q, a, b);\n";
            body += indentation + "assert Inv(q, i, min, max);\n";
            body += indentation + "L1(q, a, b, i, min, max);\n";
            body += indentation + "assert MinElement(min, q);\n";
            body += indentation + "assert MaxElement(max, q);\n";

            string lemma = "";

            lemma += "lemma L1(q: seq<int>, a: nat, b: nat, i: nat, min: int, max: int)\n";
            lemma += indentation + "requires Inv(q, i, min, max)\n";
            lemma += indentation + "ensures MinElement(min, q)\n";
            lemma += indentation + "ensures MaxElement(max, q)\n";

            string method = "";

            method += "method MM1(q: seq<int>, a: nat, b: nat) returns(i: nat, min: int, max: int)\n";
            method += indentation + "requires 0 < |q|\n";
            method += indentation + "ensures Inv(q, i, min, max)\n";


            assertiveToolDS ds = new assertiveToolDS();

            ds.Name = "MinAndMax";
            ds.AddArgument(new Variable("q", "seq<int>"));
            ds.AddArgument(new Variable("a", "nat"));
            ds.AddArgument(new Variable("b", "nat"));
            ds.AddArgument(new Variable("b", "nat"));
            ds.AddLoclVar(new Variable("i", "nat"));
            ds.AddLoclVar(new Variable("i", "nat"));
            ds.AddRetValue(new Variable("min", "int"));
            ds.AddRetValue(new Variable("min", "int"));
            ds.AddRetValue(new Variable("max", "int"));
            ds.AddPreCond("0 < |q|");
            ds.AddPreCond("0 < |q|");
            ds.AddPostCond("MinElement(min, q)");
            ds.AddPostCond("MaxElement(max, q)");
            ds.AddPostCond("MaxElement(max, q)");
            ds.strengthenPostCond("Inv(q, i, min, max)");
            ds.strengthenPostCond("Inv(q, i, min, max)");
            ds.strengthenPostCond("Inv(q, i, min, max)");

            string name;

            name = "MM1";
            ds.NewMethod.Name = name;

            name = "L1";
            ds.StrengthLemma.Name = name;

            Assert.AreEqual(body, ds.generateBody());
            Assert.AreEqual(lemma, ds.generateStrengthLemma());
            Assert.AreEqual(method, ds.generateMethod());
        }
        public static assertiveToolDS initDs1()
        {
            assertiveToolDS ds = new assertiveToolDS();

            ds.Name = "MinAndMax'";

            ds.AddArgument(new Variable("q", "seq<int>"));
            //ds.AddArgument(new Variable("j0", "nat"));
            //ds.AddArgument(new Variable("min", "int"));
            //ds.AddArgument(new Variable("max", "int"));
            //ds.AddArgument(new Variable("a", "nat"));
            //ds.AddArgument(new Variable("b", "int"));

            ds.AddLoclVar(new Variable("i", "nat"));
            //ds.AddLoclVar(new Variable("q0", "seq<int>"));
            //ds.AddLoclVar(new Variable("j0", "int"));
            //ds.AddLoclVar(new Variable("k0", "nat"));

            ds.AddRetValue(new Variable("min", "int"));
            ds.AddRetValue(new Variable("max", "int"));

            ds.AddPreCond("0 < |q|");
            //ds.AddPreCond("|q| < 100");

            ds.AddPostCond("MinElement(min, q)");
            ds.AddPostCond("MaxElement(max, q)");
            //ds.AddPostCond("q != null");

            ds.strengthenPostCond("Inv(q, i, min, max)");
            ds.strengthenPostCond("i == |q|");

            //ds.weakenPreCond("|q| < 0");


            string name;

            name = "MM1";
            ds.NewMethod.Name = name;

            name = "L1";
            ds.WeakLemma.Name = name;

            name = "L2";
            ds.StrengthLemma.Name = name;

            return(ds);
        }
        public void GenerateBody()
        {
            string body = "";

            body += indentation + "var i : nat;\n";
            body += indentation + "var q' : seq<int>;\n";
            body += indentation + "assert 0 < |q|;\n";
            body += indentation + "i, q', min, max := MM1(q);\n";
            body += indentation + "assert Inv(q, i, min, max);\n";
            body += indentation + "assert i == |q|;\n";
            body += indentation + "L1(q, i, q', min, max);\n";
            body += indentation + "assert MinElement(min, q);\n";
            body += indentation + "assert MaxElement(max, q);\n";

            assertiveToolDS ds = new assertiveToolDS();

            ds.Name = "MinAndMax";
            ds.AddArgument(new Variable("q", "seq<int>"));
            ds.AddLoclVar(new Variable("i", "nat"));
            ds.AddLoclVar(new Variable("q'", "seq<int>"));
            ds.AddRetValue(new Variable("min", "int"));
            ds.AddRetValue(new Variable("max", "int"));
            ds.AddPreCond("0 < |q|");
            ds.AddPostCond("MinElement(min, q)");
            ds.AddPostCond("MaxElement(max, q)");
            ds.strengthenPostCond("Inv(q, i, min, max)");
            ds.strengthenPostCond("i == |q|");

            string name;

            name = "MM1";
            ds.NewMethod.Name = name;

            name = "L1";
            ds.StrengthLemma.Name = name;

            Assert.AreEqual(body, ds.generateBody());
        }
        private void button_ok_Click(object sender, EventArgs e)
        {
            try
            {
                assertiveToolDS dafnyCreate = new assertiveToolDS();

                dafnyCreate.Name = p.currentMethod.FullName;

                if (this.methodName.Text == string.Empty)
                {
                    MessageBox.Show("Please enter Method Name.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                dafnyCreate.NewMethod.Name = this.methodName.Text;
                //Add var names and types
                bool isFound = false;
                for (int i = 1; i <= this.index; i++)
                {
                    string t = String.Empty;
                    string n = String.Empty;

                    foreach (Control x in this.Controls)
                    {
                        if (x is TextBox && x.Name.StartsWith("NameBox" + i))
                        {
                            n = x.Text;
                        }
                        if (x is TextBox && x.Name.StartsWith("TypeBox" + i))
                        {
                            t = x.Text;
                        }
                        if (n != String.Empty && t != String.Empty)
                        {
                            break;
                        }
                    }
                    if (n == String.Empty)
                    {
                        continue;
                    }
                    else
                    {
                        isFound = true;
                        Variable newVar = new Variable(n, t);
                        dafnyCreate.AddLoclVar(newVar);
                    }
                }
                if (!isFound)
                {
                    MessageBox.Show("Please enter at least one variable and type.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }


                if (this.pre_cond.Enabled)
                {
                    if (pre_cond.Text == string.Empty)
                    {
                        MessageBox.Show("Please enter preCondition.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    if (preCondName.Text == string.Empty)
                    {
                        MessageBox.Show("Please enter Lema name.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    dafnyCreate.weakenPreCond(pre_cond.Text);
                    dafnyCreate.WeakLemma.Name = this.preCondName.Text;
                }

                if (this.post_cond.Enabled)
                {
                    if (post_cond.Text == string.Empty)
                    {
                        MessageBox.Show("Please enter preCondition.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    if (postLemaName.Text == string.Empty)
                    {
                        MessageBox.Show("Please enter Lema name.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    dafnyCreate.strengthenPostCond(post_cond.Text);
                    dafnyCreate.StrengthLemma.Name = this.postLemaName.Text;
                }

                // Add parser
                try
                {
                    //     DafnyCodeParser p = new DafnyCodeParser();
                    //    p.parse_file(dte.ActiveDocument.FullName, dafnyCreate.Name);

                    //vars:
                    List <String> varNames = p.get_var_names();
                    List <String> varTypes = p.get_var_types();
                    for (int i = 0; i < varNames.Count; i++)
                    {
                        Variable arg1 = new Variable(varNames[i], varTypes[i]);
                        dafnyCreate.AddArgument(arg1);
                    }

                    //ret:
                    List <String> retNames = p.get_ret_names();
                    List <String> retTypes = p.get_ret_types();
                    for (int i = 0; i < retNames.Count; i++)
                    {
                        Variable arg1 = new Variable(retNames[i], retTypes[i]);
                        dafnyCreate.AddRetValue(arg1);
                    }

                    //precond
                    List <String> precond = p.get_req();
                    for (int i = 0; i < precond.Count; i++)
                    {
                        dafnyCreate.AddPreCond(precond[i]);
                    }

                    //post
                    List <String> postcond = p.get_ens();
                    for (int i = 0; i < postcond.Count; i++)
                    {
                        dafnyCreate.AddPostCond(postcond[i]);
                    }
                }
                catch
                {
                    MessageBox.Show("Error in parsing the file.", "Parser Exeption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.Close();
                    return;
                }

                // insert text
                string pre_and_post = String.Empty;
                if (pre_cond.Enabled)
                {
                    pre_and_post += "\n\n" + dafnyCreate.generateWeakLemma();
                }
                if (post_cond.Enabled)
                {
                    pre_and_post += "\n\n" + dafnyCreate.generateStrengthLemma();
                }

                toInsert.Insert("\n{\n" + dafnyCreate.generateBody() + "}\n\n" + dafnyCreate.generateMethod() + pre_and_post + "\n");



                this.Close();
            }
            catch
            {
                MessageBox.Show("Unexpected Exeption occurred during the execution.", "Unexpected Exeption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
                return;
            }
        }
        public void args0WithSameInRet()
        {
            string body = "";

            body += indentation + "i, min, max := i0, min0, max0;\n";
            body += indentation + "assert 0 < |q| && min == q[0] && max == q[0] && i == 1;\n";
            body += indentation + "L3(q, i, min, max);\n";
            body += indentation + "assert Inv(q, i, min, max);\n";
            body += indentation + "assert i > min && max < q;\n";

            body += indentation + "i, min, max := MM3(q, i, min, max);\n";
            body += indentation + "assert Inv(q, i, min, max) && i == |q|;\n";

            string lemma = "";

            lemma += "lemma L3(q: seq<int>, i: nat, min: int, max: int)\n";
            lemma += indentation + "requires 0 < |q| && min == q[0] && max == q[0] && i == 1\n";
            lemma += indentation + "ensures Inv(q, i, min, max)\n";
            lemma += indentation + "ensures i > min && max < q\n";


            string method = "";

            method += "method MM3(q: seq<int>, i0: nat, min0: int, max0: int) returns(i: nat, min: int, max: int)\n";
            method += indentation + "requires Inv(q, i0, min0, max0)\n"; //@@@
            method += indentation + "requires i0 > min0 && max0 < q\n";  //@@@
            method += indentation + "ensures Inv(q, i, min, max) && i == |q|\n";


            assertiveToolDS ds = new assertiveToolDS();

            ds.Name = "MM2'";

            ds.AddArgument(new Variable("q", "seq<int>"));
            ds.AddArgument(new Variable("i0", "nat"));
            ds.AddArgument(new Variable("min0", "int"));
            ds.AddArgument(new Variable("max0", "int"));
            ds.AddRetValue(new Variable("i", "nat"));
            ds.AddRetValue(new Variable("min", "int"));
            ds.AddRetValue(new Variable("max", "int"));
            ds.AddPreCond("0 < |q| && min0 == q[0] && max0 == q[0] && i0 == 1");
            ds.AddPostCond("Inv(q, i, min, max) && i == |q|");
            ds.weakenPreCond("Inv(q, i, min, max)");
            ds.weakenPreCond("i > min && max < q");



            string name;

            name = "MM3";
            ds.NewMethod.Name = name;

            name = "L3";
            ds.WeakLemma.Name = name;

            name = "L2";
            ds.StrengthLemma.Name = name;

            Assert.AreEqual(body, ds.generateBody());
            Assert.AreEqual(lemma, ds.generateWeakLemma());
            Assert.AreEqual(method, ds.generateMethod());
        }
        public void WeakenPreCondition()
        {
            string body = "";

            body += indentation + "var i : nat;\n";
            body += indentation + "assert 0 < |q|;\n";
            body += indentation + "L1(q, i, min, max);\n";

            body += indentation + "assert Inv2(q, i, min, max);\n";
            body += indentation + "assert Inv3(q, i, min, max);\n";

            body += indentation + "i, min, max := MM1(q);\n";
            body += indentation + "assert MinElement(min, q);\n";
            body += indentation + "assert MaxElement(max, q);\n";

            string lemma = "";

            lemma += "lemma L1(q: seq<int>, i: nat, min: int, max: int)\n";
            lemma += indentation + "requires 0 < |q|\n";
            lemma += indentation + "ensures Inv2(q, i, min, max)\n";
            lemma += indentation + "ensures Inv3(q, i, min, max)\n";

            string method = "";

            method += "method MM1(q: seq<int>) returns(i: nat, min: int, max: int)\n";
            method += indentation + "requires Inv2(q, i, min, max)\n";
            method += indentation + "requires Inv3(q, i, min, max)\n";
            method += indentation + "ensures MinElement(min, q)\n";
            method += indentation + "ensures MaxElement(max, q)\n";


            assertiveToolDS ds = new assertiveToolDS();

            ds.Name = "MinAndMax";
            ds.AddArgument(new Variable("q", "seq<int>"));
            ds.AddLoclVar(new Variable("i", "nat"));
            ds.AddRetValue(new Variable("min", "int"));
            ds.AddRetValue(new Variable("max", "int"));
            ds.AddPreCond("0 < |q|");
            ds.AddPostCond("MinElement(min, q)");
            ds.AddPostCond("MaxElement(max, q)");
            ds.weakenPreCond("Inv2(q, i, min, max)");
            ds.weakenPreCond("Inv3(q, i, min, max)");

            string name;

            name = "MM1";
            ds.NewMethod.Name = name;

            name = "L1";
            ds.WeakLemma.Name = name;

            //Console.WriteLine("WeakenPreCondition:");
            //Console.WriteLine(body);
            //Console.WriteLine(lemma);
            //Console.WriteLine(method);
            //Console.ReadLine();

            Assert.AreEqual(body, ds.generateBody());
            Assert.AreEqual(lemma, ds.generateWeakLemma());
            Assert.AreEqual(method, ds.generateMethod());
        }
        private void button_ok_Click(object sender, EventArgs e)
        {
            try
            {
                assertiveToolDS dafnyCreate = new assertiveToolDS();
                dafnyCreate.Name = p.currentMethod.FullName;

                //validation:
                if (this.methodName.Text == string.Empty)
                {
                    MessageBox.Show("Please enter Method Name.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                if (postLemaName.Text == string.Empty)
                {
                    MessageBox.Show("Please enter Lema name.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                bool isFound = false;
                foreach (Control x in this.Controls)
                {
                    if (x is TextBox && x.Name.StartsWith("post_cond") && x.Text != String.Empty)
                    {
                        isFound = true;
                        dafnyCreate.strengthenPostCond(x.Text);
                    }
                }

                if (!isFound)
                {
                    MessageBox.Show("Please enter at least one postCondition.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                // add the new pre_condition and method

                dafnyCreate.StrengthLemma.Name = this.postLemaName.Text;
                dafnyCreate.NewMethod.Name     = this.methodName.Text;

                try
                {
                    //vars:
                    List <String> varNames = p.get_var_names();
                    List <String> varTypes = p.get_var_types();
                    for (int i = 0; i < varNames.Count; i++)
                    {
                        Variable arg1 = new Variable(varNames[i], varTypes[i]);
                        dafnyCreate.AddArgument(arg1);
                    }

                    //ret:
                    List <String> retNames = p.get_ret_names();
                    List <String> retTypes = p.get_ret_types();
                    for (int i = 0; i < retNames.Count; i++)
                    {
                        Variable arg1 = new Variable(retNames[i], retTypes[i]);
                        dafnyCreate.AddRetValue(arg1);
                    }
                    //postcond
                    List <String> precond = p.get_req();
                    for (int i = 0; i < precond.Count; i++)
                    {
                        dafnyCreate.AddPreCond(precond[i]);
                    }

                    //post

                    List <String> postcond = p.get_ens();
                    for (int i = 0; i < postcond.Count; i++)
                    {
                        dafnyCreate.AddPostCond(postcond[i]);
                    }
                }
                catch
                {
                    MessageBox.Show("Error in parsing the file.", "Parser Exeption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.Close();
                    return;
                }

                // insert text
                toInsert.Insert("{\n" + dafnyCreate.generateBody() + "}\n\n" + dafnyCreate.generateMethod() + "\n\n" + dafnyCreate.generateStrengthLemma() + "\n\n");


                this.Close();
            }
            catch
            {
                MessageBox.Show("Unexpected Exeption occurred during the execution.", "Unexpected Exeption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
                return;
            }
        }
Exemple #12
0
        private void button_ok_Click(object sender, EventArgs e)
        {
            try
            {
                assertiveToolDS dafnyCreate = new assertiveToolDS();
                TextDocument    activeDoc   = null;
                DTE             dte         = null;

                try
                {
                    dte       = Package.GetGlobalService(typeof(DTE)) as DTE;
                    activeDoc = dte.ActiveDocument.Object() as TextDocument;
                }
                catch
                {
                    MessageBox.Show("Please open a Dafny file befor using the aplication.", "File not open", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.Close();
                    return;
                }

                //get position
                var cursPoint = activeDoc.Selection.ActivePoint;

                // to insert
                TextSelection toInsert = (EnvDTE.TextSelection)(activeDoc.Selection);

                //get all text
                var text = activeDoc.CreateEditPoint(activeDoc.StartPoint).GetText(activeDoc.EndPoint);

                // get input
                string name = get_method_name(text, cursPoint);
                if (name == String.Empty)
                {
                    MessageBox.Show("Method not found.", "Method not found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.Close();
                    return;
                }
                dafnyCreate.Name = name;

                //validation:
                if (this.methodName.Text == string.Empty)
                {
                    MessageBox.Show("Please enter Method Name.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                if (preCondName.Text == string.Empty)
                {
                    MessageBox.Show("Please enter Lema name.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }


                bool isFound = false;
                foreach (Control x in this.Controls)
                {
                    if (x is TextBox && x.Name.StartsWith("pre_cond") && x.Text != String.Empty)
                    {
                        isFound = true;
                        dafnyCreate.weakenPreCond(x.Text);
                    }
                }

                if (!isFound)
                {
                    MessageBox.Show("Please enter at least one preCondition.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                // add the new pre_condition and method

                dafnyCreate.WeakLemma.Name = this.preCondName.Text;
                dafnyCreate.NewMethod.Name = this.methodName.Text;

                // input from parser
                try
                {
                    DafnyCodeParser p = new DafnyCodeParser();
                    p.parse_file(dte.ActiveDocument.FullName, dafnyCreate.Name);

                    //vars:
                    List <String> varNames = p.get_var_names();
                    List <String> varTypes = p.get_var_types();
                    for (int i = 0; i < varNames.Count; i++)
                    {
                        Variable arg1 = new Variable(varNames[i], varTypes[i]);
                        dafnyCreate.AddArgument(arg1);
                    }
                    // returns
                    List <String> retNames = p.get_ret_names();
                    List <String> retTypes = p.get_ret_types();
                    for (int i = 0; i < retNames.Count; i++)
                    {
                        Variable arg1 = new Variable(retNames[i], retTypes[i]);
                        dafnyCreate.AddRetValue(arg1);
                    }

                    // preconditions
                    List <String> precond = p.get_req();
                    for (int i = 0; i < precond.Count; i++)
                    {
                        dafnyCreate.AddPreCond(precond[i]);
                    }

                    //post conditions
                    List <String> postcond = p.get_ens();
                    for (int i = 0; i < postcond.Count; i++)
                    {
                        dafnyCreate.AddPostCond(postcond[i]);
                    }
                }
                catch
                {
                    MessageBox.Show("Error in parsing the file.", "Parser Exeption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.Close();
                    return;
                }

                // insert text
                toInsert.Insert("{\n" + dafnyCreate.generateBody() + "}\n\n" + dafnyCreate.generateMethod() + "\n\n" + dafnyCreate.generateWeakLemma() + "\n\n");
                this.Close();
            }
            catch
            {
                MessageBox.Show("Unexpected Exeption occurred during the execution.", "Unexpected Exeption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
                return;
            }
        }