Private
Public Access
Fixed stack overflow bug where the Expression referenced itself
This commit is contained in:
1 parent
d9fd3d7453
commit
7c1a4b81ab
11 files changed
+39
-6
No files matched your search
@@ -190,7 +190,7 @@ namespace Advanced_Software_Engineering {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SetVariable(string name, IValue value) {
|
public void SetVariable(string name, IValue value) {
|
||||||
variables.Add(name, value);
|
variables[name] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IValue GetVariable(string name) {
|
public IValue GetVariable(string name) {
|
||||||
|
|||||||
+5
-2
@@ -9,9 +9,9 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
private string name;
|
private string name;
|
||||||
|
|
||||||
//Common characters that people might try
|
//Common characters that people might try
|
||||||
private char[] illegalCharacters = "1234567890!?/+- \"'@#~;:><,.`¬|[]{}\\£$%^&*()".ToCharArray();
|
private static readonly char[] illegalCharacters = "1234567890!?/+- \"'@#~;:><,.`¬|[]{}\\£$%^&*()".ToCharArray();
|
||||||
|
|
||||||
private string[] illegalNames =
|
private static readonly string[] illegalNames =
|
||||||
{ "var",
|
{ "var",
|
||||||
"move", "moveto",
|
"move", "moveto",
|
||||||
"drawto", "line", "lineto",
|
"drawto", "line", "lineto",
|
||||||
@@ -73,6 +73,9 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
if (drawer.CheckVariableExists(name)) throw new Exception("Declaration failed. " + name + " has been declared before");
|
if (drawer.CheckVariableExists(name)) throw new Exception("Declaration failed. " + name + " has been declared before");
|
||||||
if (!CheckName(name)) throw new Exception("'" + name + "' name not allowed");
|
if (!CheckName(name)) throw new Exception("'" + name + "' name not allowed");
|
||||||
|
|
||||||
|
//preassign name
|
||||||
|
drawer.SetVariable(name, null);
|
||||||
|
|
||||||
//for single number assignments ["i", "=", "20"]
|
//for single number assignments ["i", "=", "20"]
|
||||||
if (assignmentStrings.Length == 3) value = ValueFactory.CreateValue(drawer, assignmentStrings[2]);
|
if (assignmentStrings.Length == 3) value = ValueFactory.CreateValue(drawer, assignmentStrings[2]);
|
||||||
|
|
||||||
|
|||||||
@@ -17,5 +17,7 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
string GetOriginalType();
|
string GetOriginalType();
|
||||||
|
|
||||||
bool isInitialised();
|
bool isInitialised();
|
||||||
|
|
||||||
|
IValue Clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -50,7 +50,7 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
|
|
||||||
public void ExecuteVerb() {
|
public void ExecuteVerb() {
|
||||||
if (!drawer.CheckVariableExists(name)) throw new Exception("Cannot update variable because it is not declared");
|
if (!drawer.CheckVariableExists(name)) throw new Exception("Cannot update variable because it is not declared");
|
||||||
drawer.SetVariable(name, value);
|
drawer.SetVariable(name, value.Clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetDescription() {
|
public string GetDescription() {
|
||||||
|
|||||||
+4
@@ -62,5 +62,9 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueObjects {
|
|||||||
public bool isInitialised() {
|
public bool isInitialised() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IValue Clone() {
|
||||||
|
return new ColorValue(this.ToColor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
@@ -45,5 +45,9 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
|||||||
public bool isInitialised() {
|
public bool isInitialised() {
|
||||||
return initialised;
|
return initialised;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IValue Clone() {
|
||||||
|
return new BoolValue(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
@@ -72,5 +72,9 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
|||||||
public int ToInt() {
|
public int ToInt() {
|
||||||
return Evaluate().ToInt();
|
return Evaluate().ToInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IValue Clone() {
|
||||||
|
return new ComparisonValue(value1, value2, op);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
@@ -48,5 +48,9 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
|||||||
public bool isInitialised() {
|
public bool isInitialised() {
|
||||||
return initialised;
|
return initialised;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IValue Clone() {
|
||||||
|
return new DoubleValue(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-2
@@ -57,7 +57,7 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
private IValue Evaluate() {
|
private IValue Evaluate() {
|
||||||
if (evaluated) return evaluatedValue;
|
if (evaluated) return evaluatedValue;
|
||||||
|
|
||||||
string outputType = variable1.GetOriginalType();
|
string outputType = variable1.Clone().GetOriginalType();
|
||||||
|
|
||||||
switch (outputType) {
|
switch (outputType) {
|
||||||
case "bool":
|
case "bool":
|
||||||
@@ -119,7 +119,7 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string GetOriginalType() {
|
public string GetOriginalType() {
|
||||||
return variable1.GetOriginalType();
|
return "expression";
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool isInitialised() {
|
public bool isInitialised() {
|
||||||
@@ -141,5 +141,9 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
public int ToInt() {
|
public int ToInt() {
|
||||||
return Evaluate().ToInt();
|
return Evaluate().ToInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IValue Clone() {
|
||||||
|
return Evaluate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
@@ -63,5 +63,9 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
|||||||
public bool isInitialised() {
|
public bool isInitialised() {
|
||||||
return initialised;
|
return initialised;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IValue Clone() {
|
||||||
|
return new IntValue(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
@@ -44,5 +44,9 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
|||||||
public int ToInt() {
|
public int ToInt() {
|
||||||
return get().ToInt();
|
return get().ToInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IValue Clone() {
|
||||||
|
return new VariableValue(drawer, variableName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user