public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { //Console.WriteLine("Assignment is being executed"); Boolean Result = false; String AssignedValue = this.AssignedExpression.Evaluate(Scope, OALProgram.ExecutionSpace); if (AssignedValue == null) { return(Result); } // If we are assigning to a variable if (this.AttributeName == null) { //Console.WriteLine("Assigning value: " + AssignedValue + " to variable " + this.VariableName); EXEPrimitiveVariable Variable = Scope.FindPrimitiveVariableByName(this.VariableName); // If the variable doesnt exist, we simply create it if (Variable == null) { //Console.WriteLine("Creating new var " + this.VariableName); Result = Scope.AddVariable(new EXEPrimitiveVariable(this.VariableName, AssignedValue)); } //If variable exists and its type is UNDEFINED else if (EXETypes.UnitializedName.Equals(Variable.Type)) { //Console.WriteLine("Assigning to unitialized var" + this.VariableName); Result = Variable.AssignValue(Variable.Name, AssignedValue); } // If the variable exists and is primitive else if (!EXETypes.ReferenceTypeName.Equals(Variable.Type)) { //Console.WriteLine("Assigning to initialized var" + this.VariableName); // If the types don't match, this fails and returns false AssignedValue = EXETypes.AdjustAssignedValue(Variable.Type, AssignedValue); Result = Variable.AssignValue("", AssignedValue); } // Variable exists and is not primitive. What to do, what to do? // We do nothing, we CANNOT ASSIGN TO HANDLES!!! } // We are assigning to an attribute of a variable else { EXEReferenceEvaluator RefEvaluator = new EXEReferenceEvaluator(); Result = RefEvaluator.SetAttributeValue(this.VariableName, this.AttributeName, Scope, OALProgram.ExecutionSpace, AssignedValue); //Console.WriteLine("Tried to assign " + AssignedValue + " to " + this.VariableName + "." + this.AttributeName); } //Console.WriteLine("Assignment Result: " + Result); return(Result); }
public String Evaluate(EXEScope Scope, CDClassPool ExecutionSpace) { String Result = null; EXEExpressionEvaluator Evaluator = new EXEExpressionEvaluator(); EXEEvaluatorHandleOperators HandleEvaluator = new EXEEvaluatorHandleOperators(); EXEReferenceEvaluator AccessEvaluator = new EXEReferenceEvaluator(); // If we just calculate with ints, reals, bools, strings if (Evaluator.IsSimpleOperator(this.Operation)) { List <String> EvaluatedOperands = new List <String>(); foreach (EXEASTNode Operand in this.Operands) { EvaluatedOperands.Add(Operand.Evaluate(Scope, ExecutionSpace)); } if (EvaluatedOperands.Contains(null)) { return(Result); } //If we are returning real number, let's format it so that we don't have trouble with precision Result = Evaluator.Evaluate(this.Operation, EvaluatedOperands); /*Console.Write("AST Composite operation " + this.Operation + " has result "); * Console.Write(Result == null ? "null" : Result); * Console.WriteLine();*/ if (Result == null) { return(Result); } /* Console.WriteLine("Operation: " + this.Operation); * Console.WriteLine("Result of operation" + (Result == null ? "null" : Result));*/ if (EXETypes.RealTypeName.Equals(EXETypes.DetermineVariableType("", Result))) { //Console.WriteLine("is real and needs formatting"); if (!Result.Contains(".")) { Result = FormatDouble(Result); } if (!Result.Contains(".")) { Result += ".0"; } } } // If we have handle operators else if (HandleEvaluator.IsHandleOperator(this.Operation)) { Console.WriteLine("We have handle operator"); Result = HandleEvaluator.Evaluate(this.Operation, this.Operands.Select(x => ((EXEASTNodeLeaf)x).GetNodeValue()).ToList(), Scope); } // If we have access operator - we either access attribute or have decimal number. There are always 2 operands else if (".".Equals(this.Operation) && this.Operands.Count == 2) { if (EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) && EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue())) ) { Result = this.Operands[0].GetNodeValue() + "." + this.Operands[1].GetNodeValue(); } else if (EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) && EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue())) ) { Result = AccessEvaluator.EvaluateAttributeValue(this.Operands[0].GetNodeValue(), this.Operands[1].GetNodeValue(), Scope, ExecutionSpace); } } return(Result); }
public bool VerifyReferences(EXEScope Scope, CDClassPool ExecutionSpace) { bool Result = false; EXEExpressionEvaluator Evaluator = new EXEExpressionEvaluator(); EXEEvaluatorHandleOperators HandleEvaluator = new EXEEvaluatorHandleOperators(); EXEReferenceEvaluator AccessEvaluator = new EXEReferenceEvaluator(); // If we just calculate with ints, reals, bools, strings if (Evaluator.IsSimpleOperator(this.Operation)) { foreach (EXEASTNode Operand in this.Operands) { if (!Operand.VerifyReferences(Scope, ExecutionSpace)) { return(false); } } Result = true; } // If we have handle operators else if (HandleEvaluator.IsHandleOperator(this.Operation)) { if (this.Operands.Count() == 1 && Scope.FindReferenceHandleByName(((EXEASTNodeLeaf)this.Operands[0]).GetNodeValue()) != null) { Result = true; } } // If we have access operator - we either access attribute or have decimal number. There are always 2 operands else if (".".Equals(this.Operation) && this.Operands.Count == 2) { if (EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) && EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue())) ) { Result = true; } else if (EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) && EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue())) ) { EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.Operands[0].GetNodeValue()); if (Variable == null) { return(false); } CDClass Class = ExecutionSpace.getClassByName(Variable.ClassName); if (Class == null) { return(false); } CDAttribute Attribute = Class.GetAttributeByName(this.Operands[1].GetNodeValue()); if (Attribute == null) { return(false); } CDClassInstance Instance = Variable.RetrieveReferencedClassInstance(ExecutionSpace); if (Instance == null) { return(false); } Result = true; } } return(Result); }