public void ShouldSimplifyConstantEqualsNil_2()
        {
            var someConst = new ConstantValueNode(DataValueType.String, "abc");
            var expr      = someConst != ExpressionNode.Nil;

            expr.Should().BeEquivalentTo(new ConstantValueNode(DataValueType.Boolean, true));
        }
        public void ShouldSimplifyLogical_4()
        {
            var someConst = new ConstantValueNode(DataValueType.String, "abc");
            var someId    = new IdentifierNode("someId", DataValueType.String);
            var expr      = someConst != ExpressionNode.Nil && someId == ExpressionNode.Nil;

            expr.Should().BeEquivalentTo(someId == ExpressionNode.Nil);
        }
Beispiel #3
0
        public void TestFirstValueNode()
        {
            var node      = new Node("", "", null);
            var valueNode = new ConstantValueNode <int>("", "", 0, 0, null);

            node.Leafs.Add(valueNode);

            Assert.IsTrue(node.FirstValueNodeOrDefault <int>() != null);
            Assert.IsTrue(node.FirstValueNodeOrDefault <float>() == null);
        }
Beispiel #4
0
        public void TestFirstValue()
        {
            var node      = new Node("", "", null);
            var valueNode = new ConstantValueNode <int>("", "", 0, 100, null);

            node.Leafs.Add(valueNode);

            Assert.IsTrue(node.FirstValue <int>() == 100);
            Assert.Throws <EvaluatorException>(() => node.FirstValue <string>());
        }
Beispiel #5
0
        public void TestFirstOrDefaultValue()
        {
            var node      = new Node("", "", null);
            var valueNode = new ConstantValueNode <int>("", "", 0, 100, null);

            node.Leafs.Add(valueNode);

            Assert.IsTrue(node.FirstValueOrDefault <int>() == 100);
            Assert.IsTrue(node.FirstValueOrDefault <string>() == default(string));
        }
Beispiel #6
0
        public void TestIsValueNode()
        {
            var node = new Node("", "", null);

            Assert.IsFalse(node.IsValueNode());

            var valueNode = new ConstantValueNode <int>("", "", 0, 0, null);

            Assert.IsTrue(valueNode.IsValueNode());
            Assert.IsTrue(valueNode.IsValueNode <int>());
            Assert.IsFalse(valueNode.IsValueNode <float>());
        }
Beispiel #7
0
        public void TestContainsValueNode()
        {
            var node = new Node("", "", null);

            Assert.IsFalse(node.ContainsValueNode());

            var valueNode = new ConstantValueNode <int>("", "", 0, 0, null);

            node.Leafs.Add(valueNode);

            Assert.IsTrue(node.ContainsValueNode());
            Assert.IsTrue(node.ContainsValueNode <int>());
            Assert.IsFalse(node.ContainsValueNode <float>());
        }
Beispiel #8
0
        private double EvalNode(Node node) // Evaluate each node in expression tree recursively
        {
            ConstantValueNode constantNode = node as ConstantValueNode;

            if (constantNode != null)
            {
                return(constantNode.Value);
            }

            VariableNode variableNode = node as VariableNode;

            if (variableNode != null)
            {
                return(_variables[variableNode.VariableName]);
            }

            OperationNode operationNode = node as OperationNode;

            if (operationNode != null)
            {
                switch (operationNode.Operator)
                {
                case '+':
                    return(EvalNode(operationNode.Left) + EvalNode(operationNode.Right));

                case '-':
                    return(EvalNode(operationNode.Left) - EvalNode(operationNode.Right));

                case '*':
                    return(EvalNode(operationNode.Left) * EvalNode(operationNode.Right));

                case '/':
                    return(EvalNode(operationNode.Left) / EvalNode(operationNode.Right));

                default:
                    Console.WriteLine("Not a valid operator: " + operationNode.Operator);
                    return(0);
                }
            }
            Console.WriteLine("Not a valid node."); // error
            return(0);
        }
Beispiel #9
0
    private void ContextMenuCallback(object data)
    {
        string name = data.ToString();

        if (name == "inputNode")
        {
            BaseNode inputNode = new BaseNode();
            inputNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 150);
            nodes.Add(inputNode);
        }
        if (name == "constantValueNode")
        {
            ConstantValueNode inputNode = new ConstantValueNode();
            inputNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 60);
            nodes.Add(inputNode);
        }
        if (name == "deleteNode")
        {
            if (clickedOnNode)
            {
                BaseNode selectedNode = nodes [selectedNodeIndex];
                nodes.RemoveAt(selectedNodeIndex);

                foreach (BaseNode baseNode in nodes)
                {
                    baseNode.NodeDeleted(selectedNode);
                }
            }
        }
        if (name == "makeTransition")
        {
            if (clickedOnNode)
            {
                selectedNode       = nodes [selectedNodeIndex];
                isMakingTransition = true;
            }
        }
    }
            public bool VisitConstantValueNode(ConstantValueNode node, CompilationState state)
            {
                switch (node.DataType)
                {
                case DataValueType.Boolean:
                    var boolVal = (bool)node.Value;
                    state.Write(boolVal ? "true" : "false");
                    break;

                case DataValueType.Integer:
                case DataValueType.Float:
                    state.Write(node.Value.ToString());
                    break;

                case DataValueType.String:
                    WriteString(state, node.Value.ToString());
                    break;

                default: throw new LuaCompilationException($"Unable to write constant value node with data type '{node.DataType}'");
                }

                return(true);
            }
 public EnumResolver(object arg)
 {
     _res = (ConstantValueNode)_map[(Aggregate)arg];
 }
 public EnumResolver(object arg)
 {
     _res = (ConstantValueNode)_map[(Exclude)arg];
 }
 public EnumResolver(object arg)
 {
     _res = (ConstantValueNode)_map[(SetOperation)arg];
 }