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;
            }
        }
        public DialogResult ShowDialog()
        {
            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(DialogResult.Abort);
            }

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

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

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

            // get input to spesific class
            // 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(DialogResult.Abort);
            }
            label1.Text = "To introduce local variable for the method \"" + name + "\", please fill the fields below:";
            try
            {
                //parsing
                p.parse_file(dte.ActiveDocument.FullName, name);

                //adding pre conditions
                List <String> precond = p.get_req();
                this.pre_lable.Text        = string.Join("\n", precond);
                this.pre_cond.Location     = new Point(this.pre_cond.Location.X, this.pre_cond.Location.Y + 10 * precond.Count);
                this.lableLemaPre.Location = new Point(this.lableLemaPre.Location.X, this.lableLemaPre.Location.Y + 10 * precond.Count);
                this.preCondName.Location  = new Point(this.preCondName.Location.X, this.preCondName.Location.Y + 10 * precond.Count);

                //adding post conditions
                List <String> postcond = p.get_ens();
                this.post_lable.Text        = string.Join("\n", postcond);
                this.post_cond.Location     = new Point(this.post_cond.Location.X, this.post_cond.Location.Y + 10 * postcond.Count + 10 * precond.Count);
                this.postLemaName.Location  = new Point(this.postLemaName.Location.X, this.postLemaName.Location.Y + 10 * postcond.Count + 10 * precond.Count);
                this.lableLemaPost.Location = new Point(this.lableLemaPost.Location.X, this.lableLemaPost.Location.Y + 10 * postcond.Count + 10 * precond.Count);
                this.checkBox2.Location     = new Point(this.checkBox2.Location.X, this.checkBox2.Location.Y + 10 * precond.Count);
                this.label5.Location        = new Point(this.label5.Location.X, this.label5.Location.Y + 10 * precond.Count);
                this.post_lable.Location    = new Point(this.label5.Location.X, this.label5.Location.Y + 10 * precond.Count);


                this.Height += 10 * postcond.Count + 10 * precond.Count;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Exception caught during parsing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                // this.Close();
                return(DialogResult.Abort);
            }
            return(base.ShowDialog());
        }
Beispiel #3
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;
            }
        }