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