private void assignmentToolStripMenuItem_Click(object sender, EventArgs e) { AssignmentForm assignmentForm = new AssignmentForm(Scope.LocalVariables); if (assignmentForm.ShowDialog() != DialogResult.OK) { return; } if (assignmentForm.Assignment == null) { return; } AssignmentBlock assignmentBlock = new AssignmentBlock(assignmentForm.Assignment, true); ScopePanel.Controls.Add(assignmentBlock); UpdateScope(); }
//Pass the the items of a scope and it will generate necessary controls public void VcodeToVblock(Scope scope) { foreach (VCode item in scope.Items) { switch (item.VType) { case Enums.VType.Variable: Vvariable vvariable = new Vvariable(item); ScopePanel.Controls.Add(vvariable); break; case Enums.VType.Function: Function function = (Function)item; if (function.IsBody) { Vfunction vfunction = new Vfunction(function) { Width = ScopePanel.Width }; vfunction.ScopeControl.VcodeToVblock(function.Scope); ScopePanel.Controls.Add(vfunction); } else { FunctionCall vFunctionCall = new FunctionCall(function, scope.LocalVariables); ScopePanel.Controls.Add(vFunctionCall); } break; case Enums.VType.If: If iif = (If)item; Vif vif = new Vif(iif) { Width = ScopePanel.Width }; vif.ScopeControl.VcodeToVblock(iif.Scope); ScopePanel.Controls.Add(vif); break; case Enums.VType.While: While wWhile = (While)item; Vwhile vwhile = new Vwhile(wWhile) { Width = ScopePanel.Width }; vwhile.ScopeControl.VcodeToVblock(wWhile.Scope); ScopePanel.Controls.Add(vwhile); break; case Enums.VType.Assignment: Assignment assignment = (Assignment)item; AssignmentBlock assignmentBlock = new AssignmentBlock(assignment, false); ScopePanel.Controls.Add(assignmentBlock); break; default: throw new ArgumentOutOfRangeException(); } } }