//Pass the the items of a scope and it will generate necessary controls public void VcodeToVblock(Scope scope) { GlobalScopePanel.Controls.Clear(); foreach (VCode item in scope.Items) { switch (item.VType) { case Enums.VType.Variable: Vvariable vvariable = new Vvariable(item); GlobalScopePanel.Controls.Add(vvariable); break; case Enums.VType.Function: Function function = (Function)item; Vfunction vfunction = new Vfunction(function) { Width = GlobalScopePanel.Width }; vfunction.ScopeControl.VcodeToVblock(function.Scope); GlobalScopePanel.Controls.Add(vfunction); break; } } }
private void FunctionToolStripMenuItem1_Click(object sender, EventArgs e) { FunctionProperties functionProperties = new FunctionProperties(); if (functionProperties.ShowDialog() != DialogResult.OK) { return; } Vfunction vFunc = new Vfunction(functionProperties.Function) { Width = GlobalScopePanel.Width }; foreach (var variable in GlobalScope.Scope.LocalVariables) { vFunc.Function.Scope.ScopeAccessVariable.Add(variable); } foreach (var var in functionProperties.Function.Parameters) { vFunc.Function.Scope.ScopeAccessVariable.Add(new Variable(var.Name) { Type = var.Type }); } vFunc.SetReturnVar(); GlobalScopePanel.Controls.Add(vFunc); GlobalScope.FunctionList.Add(functionProperties.Function); UpdateScope(); }
private void mainToolStripMenuItem_Click(object sender, EventArgs e) { Function mainFunction = new Function { Name = "Main", IsBody = true, VType = Enums.VType.Function, Type = Enums.Type.Void }; Vfunction vFunc = new Vfunction(mainFunction) { Width = GlobalScopePanel.Width, settingsButton = { Visible = false } }; vFunc.Function.Scope.ScopeAccessVariable = GlobalScope.Scope.LocalVariables; GlobalScopePanel.Controls.Add(vFunc); MainFunctionDeclared = true; 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(); } } }