Private
Public Access
Code cleanup
This commit is contained in:
1 parent
72b5db624f
commit
39dc69d7b1
11 files changed
+44
-65
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
||||||
</startup>
|
</startup>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -12,8 +12,7 @@ namespace Advanced_Software_Engineering {
|
|||||||
/// The drawer is responsible for drawing on the graphics object.
|
/// The drawer is responsible for drawing on the graphics object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Drawer {
|
public class Drawer {
|
||||||
|
private readonly ValueStorage valueStorage = new ValueStorage();
|
||||||
private ValueStorage valueStorage = new ValueStorage();
|
|
||||||
public List<IVerbChunk> verbChunks = new List<IVerbChunk>();
|
public List<IVerbChunk> verbChunks = new List<IVerbChunk>();
|
||||||
public bool verbChunkGeneratingMethod = false;
|
public bool verbChunkGeneratingMethod = false;
|
||||||
public Dictionary<string, MethodChunk> Methods = new Dictionary<string, MethodChunk>();
|
public Dictionary<string, MethodChunk> Methods = new Dictionary<string, MethodChunk>();
|
||||||
@@ -153,8 +152,8 @@ namespace Advanced_Software_Engineering {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Make it relative to the pen
|
//Make it relative to the pen
|
||||||
for (int pointIndex = 0; pointIndex < points.Length; pointIndex++)
|
for (int pointIndex = 0; pointIndex < points.Length; pointIndex++)
|
||||||
points[pointIndex] = new Point(points[pointIndex].X + penPosition.X, points[pointIndex].Y+ penPosition.Y);
|
points[pointIndex] = new Point(points[pointIndex].X + penPosition.X, points[pointIndex].Y + penPosition.Y);
|
||||||
|
|
||||||
GraphicsPath path = new GraphicsPath {
|
GraphicsPath path = new GraphicsPath {
|
||||||
FillMode = FillMode.Winding
|
FillMode = FillMode.Winding
|
||||||
@@ -202,6 +201,5 @@ namespace Advanced_Software_Engineering {
|
|||||||
public ValueStorage GetValueStorage() {
|
public ValueStorage GetValueStorage() {
|
||||||
return valueStorage;
|
return valueStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-3
@@ -1,11 +1,12 @@
|
|||||||
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs.Actions {
|
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs.Actions {
|
||||||
class NoOp : IVerb {
|
|
||||||
public void ExecuteVerb() {
|
|
||||||
|
|
||||||
|
internal class NoOp : IVerb {
|
||||||
|
|
||||||
|
public void ExecuteVerb() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetDescription() {
|
public string GetDescription() {
|
||||||
return "NoOp";
|
return "NoOp";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-13
@@ -1,15 +1,8 @@
|
|||||||
using Advanced_Software_Engineering.Verbs.Value;
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
|
||||||
class DeclareMethod : IVerb, IVerbChunk {
|
|
||||||
string methodName;
|
|
||||||
Drawer drawer;
|
|
||||||
|
|
||||||
|
internal class DeclareMethod : IVerb, IVerbChunk {
|
||||||
|
private readonly string methodName;
|
||||||
|
private readonly Drawer drawer;
|
||||||
|
|
||||||
public DeclareMethod(Drawer drawer, string methodName) {
|
public DeclareMethod(Drawer drawer, string methodName) {
|
||||||
this.drawer = drawer;
|
this.drawer = drawer;
|
||||||
@@ -19,7 +12,7 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
|||||||
public void AddVerb(IVerb verb) {
|
public void AddVerb(IVerb verb) {
|
||||||
MethodChunk methodChunk = drawer.Methods[methodName];
|
MethodChunk methodChunk = drawer.Methods[methodName];
|
||||||
methodChunk.AddVerb(verb);
|
methodChunk.AddVerb(verb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExecuteVerb() {
|
public void ExecuteVerb() {
|
||||||
//Declaration of method happens at parse time
|
//Declaration of method happens at parse time
|
||||||
@@ -29,4 +22,4 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
|||||||
return "Declares a method";
|
return "Declares a method";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-7
@@ -1,15 +1,11 @@
|
|||||||
using System;
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
|
||||||
public interface IVerbChunk : IVerb {
|
public interface IVerbChunk : IVerb {
|
||||||
|
|
||||||
void AddVerb(IVerb verb);
|
void AddVerb(IVerb verb);
|
||||||
|
|
||||||
void ExecuteVerb();
|
void ExecuteVerb();
|
||||||
|
|
||||||
string GetDescription();
|
string GetDescription();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
public class IfChunk : VerbChunk, IVerbChunk, IVerb {
|
|
||||||
|
|
||||||
IValue conditional;
|
public class IfChunk : VerbChunk, IVerbChunk, IVerb {
|
||||||
ValueStorage valueStorage;
|
private readonly IValue conditional;
|
||||||
|
private readonly ValueStorage valueStorage;
|
||||||
|
|
||||||
public IfChunk(ValueStorage valueStorage, IValue conditional) : base() {
|
public IfChunk(ValueStorage valueStorage, IValue conditional) : base() {
|
||||||
this.conditional = conditional;
|
this.conditional = conditional;
|
||||||
@@ -24,6 +24,5 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
|||||||
if (conditional.ToBool()) base.ExecuteVerb();
|
if (conditional.ToBool()) base.ExecuteVerb();
|
||||||
valueStorage.DecreaseStack();
|
valueStorage.DecreaseStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+7
-9
@@ -1,16 +1,15 @@
|
|||||||
using Advanced_Software_Engineering.Verbs.Value;
|
using Advanced_Software_Engineering.Verbs.Value;
|
||||||
using Advanced_Software_Engineering.Verbs.Value.ValueTypes;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
public class MethodChunk : VerbChunk, IVerb, IValue {
|
|
||||||
|
|
||||||
ValueStorage valueStorage;
|
public class MethodChunk : VerbChunk, IVerb, IValue {
|
||||||
DeclareVariable[] variables;
|
private readonly ValueStorage valueStorage;
|
||||||
UpdateVariable[] updateVariables;
|
private readonly DeclareVariable[] variables;
|
||||||
bool init = false;
|
private UpdateVariable[] updateVariables;
|
||||||
IValue result;
|
private bool init = false;
|
||||||
|
private IValue result;
|
||||||
|
|
||||||
public MethodChunk(ValueStorage valueStorage, DeclareVariable[] variables) : base() {
|
public MethodChunk(ValueStorage valueStorage, DeclareVariable[] variables) : base() {
|
||||||
this.valueStorage = valueStorage;
|
this.valueStorage = valueStorage;
|
||||||
@@ -59,7 +58,6 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
|||||||
init = true;
|
init = true;
|
||||||
}
|
}
|
||||||
valueStorage.DecreaseStack();
|
valueStorage.DecreaseStack();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IValue GetResult() {
|
public IValue GetResult() {
|
||||||
@@ -94,4 +92,4 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
|||||||
return GetResult().ToInt();
|
return GetResult().ToInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-5
@@ -2,10 +2,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
public class WhileChunk : VerbChunk, IVerbChunk, IVerb {
|
|
||||||
|
|
||||||
IValue conditional;
|
public class WhileChunk : VerbChunk, IVerbChunk, IVerb {
|
||||||
ValueStorage valueStorage;
|
private readonly IValue conditional;
|
||||||
|
private readonly ValueStorage valueStorage;
|
||||||
|
|
||||||
public WhileChunk(ValueStorage valueStorage, IValue conditional) : base() {
|
public WhileChunk(ValueStorage valueStorage, IValue conditional) : base() {
|
||||||
this.conditional = conditional;
|
this.conditional = conditional;
|
||||||
@@ -24,6 +24,5 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
|||||||
while (conditional.ToBool()) base.ExecuteVerb();
|
while (conditional.ToBool()) base.ExecuteVerb();
|
||||||
valueStorage.DecreaseStack();
|
valueStorage.DecreaseStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-4
@@ -2,8 +2,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.Value {
|
namespace Advanced_Software_Engineering.Verbs.Value {
|
||||||
public class ValueStorage {
|
|
||||||
|
|
||||||
|
public class ValueStorage {
|
||||||
protected int currentStack;
|
protected int currentStack;
|
||||||
protected List<Dictionary<string, IValue>> Variables = new List<Dictionary<string, IValue>>();
|
protected List<Dictionary<string, IValue>> Variables = new List<Dictionary<string, IValue>>();
|
||||||
|
|
||||||
@@ -21,9 +21,9 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
if (stack < 0) throw new Exception("Stack cannot be less than 0");
|
if (stack < 0) throw new Exception("Stack cannot be less than 0");
|
||||||
|
|
||||||
//Decreased Stack
|
//Decreased Stack
|
||||||
if(currentStack > stack) {
|
if (currentStack > stack) {
|
||||||
Variables.RemoveAt(currentStack);
|
Variables.RemoveAt(currentStack);
|
||||||
}
|
}
|
||||||
//Increased Stack
|
//Increased Stack
|
||||||
else if (currentStack < stack) {
|
else if (currentStack < stack) {
|
||||||
Variables.Add(new Dictionary<string, IValue>());
|
Variables.Add(new Dictionary<string, IValue>());
|
||||||
@@ -80,4 +80,4 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -13,7 +13,7 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
private readonly IValue variable2;
|
private readonly IValue variable2;
|
||||||
private readonly int operation;
|
private readonly int operation;
|
||||||
|
|
||||||
private bool evaluated = false;
|
private readonly bool evaluated = false;
|
||||||
private IValue evaluatedValue;
|
private IValue evaluatedValue;
|
||||||
|
|
||||||
public ExpressionValue(IValue variable1, IValue variable2, int operation) {
|
public ExpressionValue(IValue variable1, IValue variable2, int operation) {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ namespace Advanced_Software_Engineering {
|
|||||||
public static IVerb MakeVerb(Drawer drawer, string fullCommand) {
|
public static IVerb MakeVerb(Drawer drawer, string fullCommand) {
|
||||||
ValueStorage rootValueStorage = drawer.GetValueStorage();
|
ValueStorage rootValueStorage = drawer.GetValueStorage();
|
||||||
|
|
||||||
|
|
||||||
List<IVerbChunk> verbChunks = drawer.verbChunks;
|
List<IVerbChunk> verbChunks = drawer.verbChunks;
|
||||||
if (verbChunks.Count == 0) verbChunks.Add(null);
|
if (verbChunks.Count == 0) verbChunks.Add(null);
|
||||||
|
|
||||||
@@ -78,7 +77,6 @@ namespace Advanced_Software_Engineering {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Parse flow verbs
|
//Parse flow verbs
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "if":
|
case "if":
|
||||||
@@ -91,7 +89,7 @@ namespace Advanced_Software_Engineering {
|
|||||||
} else if (commandParameters.Length >= 2) { //single line if
|
} else if (commandParameters.Length >= 2) { //single line if
|
||||||
string commandAfterIf = fullCommand.Substring(fullCommand.IndexOf(",") + 1); // find the first ,
|
string commandAfterIf = fullCommand.Substring(fullCommand.IndexOf(",") + 1); // find the first ,
|
||||||
IValue conditional = ValueFactory.CreateValue(rootValueStorage, commandParameters[0]); //make the conditional
|
IValue conditional = ValueFactory.CreateValue(rootValueStorage, commandParameters[0]); //make the conditional
|
||||||
IVerb AfterIf = MakeVerb(drawer, commandAfterIf); //make the following command
|
IVerb AfterIf = MakeVerb(drawer, commandAfterIf); //make the following command
|
||||||
tmpVerb = new IfChunk(rootValueStorage, conditional, AfterIf); //Create the chunk
|
tmpVerb = new IfChunk(rootValueStorage, conditional, AfterIf); //Create the chunk
|
||||||
parsed = true;
|
parsed = true;
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
@@ -107,7 +105,7 @@ namespace Advanced_Software_Engineering {
|
|||||||
} else if (commandParameters.Length >= 2) { //single line if
|
} else if (commandParameters.Length >= 2) { //single line if
|
||||||
string commandAfterIf = fullCommand.Substring(fullCommand.IndexOf(",") + 1); // find the first ,
|
string commandAfterIf = fullCommand.Substring(fullCommand.IndexOf(",") + 1); // find the first ,
|
||||||
IValue conditional = ValueFactory.CreateValue(rootValueStorage, commandParameters[0]); //make the conditional
|
IValue conditional = ValueFactory.CreateValue(rootValueStorage, commandParameters[0]); //make the conditional
|
||||||
IVerb AfterIf = MakeVerb(drawer, commandAfterIf); //make the following command
|
IVerb AfterIf = MakeVerb(drawer, commandAfterIf); //make the following command
|
||||||
tmpVerb = new WhileChunk(rootValueStorage, conditional, AfterIf); //Create the chunk
|
tmpVerb = new WhileChunk(rootValueStorage, conditional, AfterIf); //Create the chunk
|
||||||
parsed = true;
|
parsed = true;
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
@@ -162,22 +160,20 @@ namespace Advanced_Software_Engineering {
|
|||||||
//Handle errors
|
//Handle errors
|
||||||
if (methodVariableNames.Length != parameterLength) throw new Exception("Method " + command + "Has an incorrect number of parameters");
|
if (methodVariableNames.Length != parameterLength) throw new Exception("Method " + command + "Has an incorrect number of parameters");
|
||||||
|
|
||||||
|
|
||||||
/* So something like this:
|
/* So something like this:
|
||||||
* def abc d
|
* def abc d
|
||||||
* circle d
|
* circle d
|
||||||
*
|
*
|
||||||
* abc 5
|
* abc 5
|
||||||
*
|
*
|
||||||
* would have to be translated into something like this
|
* would have to be translated into something like this
|
||||||
* @increase stack
|
* @increase stack
|
||||||
* var d = 5 (of course in a higher stack)
|
* var d = 5 (of course in a higher stack)
|
||||||
*
|
*
|
||||||
* @run abc (abc doesn't increase it's own stack)
|
* @run abc (abc doesn't increase it's own stack)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Update the values of the variables
|
// Update the values of the variables
|
||||||
List<UpdateVariable> UpdateVariableList = new List<UpdateVariable>();
|
List<UpdateVariable> UpdateVariableList = new List<UpdateVariable>();
|
||||||
for (int variableIndex = 0; variableIndex < methodVariableNames.Length; variableIndex++) {
|
for (int variableIndex = 0; variableIndex < methodVariableNames.Length; variableIndex++) {
|
||||||
@@ -338,7 +334,6 @@ namespace Advanced_Software_Engineering {
|
|||||||
tmpVerb = currentChunk;
|
tmpVerb = currentChunk;
|
||||||
currentChunk = verbChunks[chunkDepth];
|
currentChunk = verbChunks[chunkDepth];
|
||||||
rootValueStorage.DecreaseStack();
|
rootValueStorage.DecreaseStack();
|
||||||
|
|
||||||
} else throw new Exception(command + " doesn't take parameters");
|
} else throw new Exception(command + " doesn't take parameters");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user