Пример #1
0
        public void Visit(NotNode n)
        {
            var child = n.GetChildren().Single();

            child.Accept(this);
            n.ExprType = child.ExprType;
        }
Пример #2
0
        public void NotNotNodeTest()
        {
            var inputNode  = new InputNode("in", new State(true));
            var notNode1   = new NotNode("not1");
            var notNode2   = new NotNode("not2");
            var outputNode = new OutputNode("out");

            var nodeConnections = new List <NodeConnection>
            {
                new NodeConnection(inputNode, notNode1),
                new NodeConnection(notNode1, notNode2),
                new NodeConnection(notNode2, outputNode)
            };

            var inputNodes = new List <InputNode>
            {
                inputNode
            };

            var simulation = new NodeSimulation(nodeConnections);

            simulation.RunSimulation();

            var output = simulation.GetOutputState();

            Assert.True(output["out"].LogicState);
        }
 private Value Not(NotNode exp)
 {
     try
     {
         Constant  node = Eval(exp.InnerNode).GetRValue();
         BoolValue n    = (BoolValue)Convert(node, Constant.Type.Bool);
         return(BoolValue.OpNot(n));
     }
     catch (TypeConversionError exc)
     {
         throw new ModelInterpreterException($"Операция \"НЕ\" не определена для типов \"{exc.Src}\" и \"{exc.Dst}\"")
               {
                   Line     = exp.Line,
                   Position = exp.Position
               };
     }
     catch (Exception exc)
     {
         throw new ModelInterpreterException(exc.Message)
               {
                   Line     = exp.Line,
                   Position = exp.Position
               };
     }
 }
Пример #4
0
        public void Visit(NotNode n)
        {
            var children     = n.GetChildren();
            var table        = (FunctionSymbolTableEntry)n.SymTable;
            var resultOffset = table.MemoryLayout.GetOffset(n.TemporaryVariableName);

            var operandVarOffsets = new List <int>();

            foreach (var child in children)
            {
                child.Accept(this);
                var offset = table.MemoryLayout.GetOffset(child.TemporaryVariableName);
                operandVarOffsets.Add(offset);
            }

            _writer.WriteComment($"Not at ({n.Token.StartLine}:{n.Token.StartColumn})");

            var opReg   = PopRegister();
            var destReg = PopRegister();

            _writer.WriteInstruction(Instructions.Lw, opReg, $"{operandVarOffsets[0]}({FSPReg})");
            _writer.WriteInstruction(Instructions.Not, destReg, opReg);
            _writer.WriteInstruction(Instructions.Sw, $"{resultOffset}({FSPReg})", destReg);

            PushRegister(destReg);
            PushRegister(opReg);
        }
        protected virtual BaseQuery HandleNot(NotNode node, ElasticSearchQueryMapperState state)
        {
            var query = Handle(node.Operand, state);

            //TODO: this works for basic term queries. While the LuceneProvider is somewhat the same, the SolrProvider had extra logic presumably to handle specific cases.
            return(!query);
        }
        protected QueryBase VisitNot(NotNode node, ElasticQueryMapperState state)
        {
            // TODO: Copied from Lucene - might need extra logic as in Solr
            return(!Visit(node.Operand, state));

            // TODO: Solr implementation
            //AbstractSolrQuery abstractSolrQuery = this.Visit(node.Operand, state);
            //SolrQueryByField solrQueryByField = abstractSolrQuery as SolrQueryByField;
            //if (solrQueryByField != null && string.IsNullOrEmpty(solrQueryByField.FieldValue))
            //    return (AbstractSolrQuery)new SolrMultipleCriteriaQuery((IEnumerable<ISolrQuery>)new ISolrQuery[2]
            //    {
            //      (ISolrQuery) new SolrNotQuery((ISolrQuery) abstractSolrQuery),
            //      (ISolrQuery) new SolrHasValueQuery(solrQueryByField.FieldName)
            //    });

            //SolrNotQuery solrNotQuery = abstractSolrQuery as SolrNotQuery;

            //if (solrNotQuery != null)
            //    return (AbstractSolrQuery)solrNotQuery.Query;

            //return (AbstractSolrQuery)new SolrMultipleCriteriaQuery((IEnumerable<ISolrQuery>)new ISolrQuery[2]
            //{
            //    (ISolrQuery) new SolrNotQuery((ISolrQuery) abstractSolrQuery),
            //    (ISolrQuery) SolrQuery.All
            //});
        }
Пример #7
0
        public void CircuitValidatesLooped()
        {
            // Later change to importing the circuit from file
            var c  = new Circuit();
            var i1 = new InputNode();

            var n1 = new NotNode();
            var n2 = new NotNode();
            var n3 = new NotNode();

            c.AddInput(i1, NodeCurrent.None);
            c.Add(i1);
            c.Add(n1);
            c.Add(n2);
            c.Add(n3);

            i1.AddOutput(n1);
            n1.AddOutput(n2);
            n2.AddOutput(n3);
            n3.AddOutput(n1);


            Assert.ThrowsException <CircuitInvalidException>(() =>
            {
                c.Accept(new CircuitLoopValidatorVisitor());
            });
        }
Пример #8
0
        private IStalkNode NewSingleChildNode(XmlElement fragment)
        {
            SingleChildLogicalNode node;

            switch (fragment.Name)
            {
            case "external":
                return(NewExternalNode(fragment));

            case "not":
                node = new NotNode();
                break;

            case "expiry":
                node = new ExpiryNode();

                var timestampAttribute = fragment.Attributes["expiry"];
                if (timestampAttribute != null)
                {
                    ((ExpiryNode)node).Expiry = XmlConvert.ToDateTime(timestampAttribute.Value, XmlDateTimeSerializationMode.Utc);
                }

                break;

            default:
                throw new XmlException("Unknown element " + fragment.Name);
            }

            var child = this.NewFromXmlFragment((XmlElement)fragment.ChildNodes[0]);

            node.ChildNode = child;

            return(node);
        }
Пример #9
0
        public void ValidCheckWithLoops()
        {
            var inputNode1 = new InputNode("in1", new State(true));
            var notNode    = new NotNode("not");
            var andNode    = new AndNode("and");
            var outputNode = new OutputNode("out");

            var nodeConnections = new List <NodeConnection>
            {
                new NodeConnection(andNode, notNode),
                new NodeConnection(
                    new List <NodeBase> {
                    inputNode1, notNode
                },
                    andNode),
                new NodeConnection(andNode, outputNode)
            };

            var inputNodes = new List <InputNode>
            {
                inputNode1
            };

            var simulation = new NodeSimulation(nodeConnections);

            Assert.Throws <PathException>(() => simulation.ValidSimulationCheck());
        }
Пример #10
0
 public void Visit(NotNode node)
 {
     node.Inner[0].Accept(this);
     EstimatedCount = _log.Count - EstimatedCount;
     Index          = _log.Search().Except(Index);
     Mode           = Query.EvaluationMode.Index;
 }
Пример #11
0
        public void NodeConnectionWithNotNodeTest()
        {
            var inputNode  = new InputNode("in", new State(true));
            var notNode    = new NotNode("not");
            var outputNode = new OutputNode("out");

            var nodeConnections = new List <NodeConnection>
            {
                new NodeConnection(inputNode, notNode),
                new NodeConnection(notNode, outputNode)
            };

            var outputs = nodeConnections.Where(x => x.OutputNode is OutputNode).ToList();

            var inputIds = outputs.SelectMany(x => x.InputNodes).Select(x => x.NodeId).ToList();

            var inputConnections = nodeConnections.Where(x => inputIds.Contains(x.OutputNode.NodeId));

            foreach (var input in inputConnections)
            {
                input.GetResultFromOutputNode();
            }

            //var t = nodeConnections.Where(x => x.InputNodes.Any(y => ))

            // Get which node connection has the not node as output
            // Do GetResultFromOutputNode on that node connection

            nodeConnections[1].GetResultFromOutputNode();

            Assert.False(nodeConnections[1].OutputNode.CurrentState.LogicState);
        }
Пример #12
0
        /// <summary>
        /// Takes a list of tokenized input and create the corresponding expression tree.
        /// </summary>
        /// <param name="tokenList">
        /// Tokenized list of the input string.
        /// </param>
        private Node ConstructExpressionTree(List <Token> tokenList)
        {
            bool         notFlag  = false;
            Queue <Node> andQueue = new Queue <Node>();
            Queue <Node> orQueue  = new Queue <Node>();

            for (int i = 0; i < tokenList.Count; i++)
            {
                Token     token = tokenList[i];
                TokenKind kind  = token.Kind;
                if (kind == TokenKind.Identifier)
                {
                    Node idNode = new OperandNode(token.Text);
                    if (notFlag)    // identifier preceded by NOT
                    {
                        Node notNode = new NotNode();
                        notNode.Operand1 = idNode;
                        notFlag          = false;
                        andQueue.Enqueue(notNode);
                    }
                    else
                    {
                        andQueue.Enqueue(idNode);
                    }
                }
                else if (kind == TokenKind.Not)
                {
                    notFlag = true;
                }
                else if (kind == TokenKind.And)
                {
                    // do nothing
                }
                else if (kind == TokenKind.Or)
                {
                    // Dequeue all nodes from AND queue,
                    // create the AND tree, then add to the OR queue.
                    Node andCurrent = andQueue.Dequeue();
                    while (andQueue.Count > 0)
                    {
                        Node andNode = new AndNode(andCurrent);
                        andNode.Operand1 = andQueue.Dequeue();
                        andCurrent       = andNode;
                    }
                    orQueue.Enqueue(andCurrent);
                }
            }

            // Dequeue all nodes from OR queue,
            // create the OR tree (final expression tree)
            Node orCurrent = orQueue.Dequeue();

            while (orQueue.Count > 0)
            {
                Node orNode = new OrNode(orCurrent);
                orNode.Operand1 = orQueue.Dequeue();
                orCurrent       = orNode;
            }
            return(orCurrent);
        }
Пример #13
0
        public static NotNode BuildNonWordNode()
        {
            var word = BuildWordNode();
            var not = new NotNode(new NotToken());
            not.ChildNodes.Add(word);

            return not;
        }
Пример #14
0
        public static NotNode BuildNonWhitespaceNode()
        {
            var whitespace = BuildWhitespaceNode();
            var not = new NotNode(new NotToken());
            not.ChildNodes.Add(whitespace);

            return not;
        }
Пример #15
0
        public static NotNode BuildNonNumericNode()
        {
            var numeric = BuildNumericNode();
            var not = new NotNode(new NotToken());
            not.ChildNodes.Add(numeric);

            return not;
        }
 public void Visit(NotNode node)
 {
     Visit(node as UnaryNode);
     if (object_return_type)
     {
         Code.Add(new AssignStrToVarCodeLine(return_type, "Bool"));
     }
 }
Пример #17
0
        public void NotNodeTest()
        {
            var notNode = new NotNode("");

            notNode.Calculate(new State(false));

            Assert.True(notNode.CurrentState.LogicState);
        }
Пример #18
0
        private TypeInfo Visit(NotNode node, MethodBuilder builder, CodegenContext context)
        {
            var res = Visit(node.Operand as dynamic, builder, context);

            builder.Not();

            return(res);
        }
Пример #19
0
 public void Visit(NotNode node)
 {
     UnaryOperationVisit(node);
     if (special_object_return_type)
     {
         SetReturnType("Bool");
     }
 }
Пример #20
0
 protected internal override void VisitNotNode(SnapshotBuilder builder, NotNode node)
 {
     if (builder.IsVisited(node))
     {
         return;
     }
     builder.AddNode(node, NodeInfo.Create);
     base.VisitNotNode(builder, node);
 }
        public override ASTN VisitNot([NotNull] NotContext context)
        {
            NotNode node = new NotNode(context)
            {
                expr = VisitExpr(context.expr()) as ExprNode
            };

            return(node);
        }
Пример #22
0
 protected internal override void VisitNotNode(SchemaBuilder builder, NotNode node)
 {
     if (builder.IsVisited(node))
     {
         return;
     }
     builder.AddNode(node, ReteNode.Create);
     base.VisitNotNode(builder, node);
 }
Пример #23
0
 public void Visit(NotNode n)
 {
     PrintDOTIDLabel(n);
     PrintDOTParentChild(n);
     foreach (var child in n.GetChildren())
     {
         child.Accept(this);
     }
 }
Пример #24
0
        public static NotNode BuildNonWhitespaceNode()
        {
            var whitespace = BuildWhitespaceNode();
            var not        = new NotNode(new NotToken());

            not.ChildNodes.Add(whitespace);

            return(not);
        }
Пример #25
0
        public static NotNode BuildNonNumericNode()
        {
            var numeric = BuildNumericNode();
            var not     = new NotNode(new NotToken());

            not.ChildNodes.Add(numeric);

            return(not);
        }
Пример #26
0
        public static NotNode BuildNonWordNode()
        {
            var word = BuildWordNode();
            var not  = new NotNode(new NotToken());

            not.ChildNodes.Add(word);

            return(not);
        }
Пример #27
0
 public override void Visit(NotNode node)
 {
     if (node.Descendant.ReturnType != typeof(bool))
     {
         AddSemanticError(node.FullSpan,
                          string.Format(AnalysisMessage.BadType, node.Descendant.ReturnType.Name, nameof(Boolean)),
                          SemanticErrorKind.MixedValues);
     }
 }
Пример #28
0
        private RdlSyntaxNode ComposeEqualityOperators()
        {
            var node = ComposeArithmeticOperators(Precendence.Level1);

            while (IsEqualityOperator(Current))
            {
                switch (Current.TokenType)
                {
                case StatementType.GreaterEqual:
                    Consume(StatementType.GreaterEqual);
                    node = new GreaterEqualNode(node, ComposeEqualityOperators());
                    break;

                case StatementType.Greater:
                    Consume(StatementType.Greater);
                    node = new GreaterNode(node, ComposeEqualityOperators());
                    break;

                case StatementType.LessEqual:
                    Consume(StatementType.LessEqual);
                    node = new LessEqualNode(node, ComposeEqualityOperators());
                    break;

                case StatementType.Less:
                    Consume(StatementType.Less);
                    node = new LessNode(node, ComposeEqualityOperators());
                    break;

                case StatementType.Equality:
                    Consume(StatementType.Equality);
                    node = new EqualityNode(node, ComposeEqualityOperators());
                    break;

                case StatementType.Diff:
                    Consume(StatementType.Diff);
                    node = new DiffNode(node, ComposeEqualityOperators());
                    break;

                case StatementType.Between:
                    node = new BetweenNode(ConsumeAndGetToken(), node,
                                           ComposeAndSkip(f => f.ComposeArithmeticOperators(Precendence.Level1), StatementType.And),
                                           ComposeArithmeticOperators(Precendence.Level1));
                    break;

                case StatementType.Not:
                    Consume(StatementType.Not);
                    node = new NotNode(Current, node);
                    break;

                default:
                    throw new NotSupportedException();
                }
            }

            return(node);
        }
Пример #29
0
        void PropagateNotToLeaves(ref IQueryNode rootNode)
        {
            if (rootNode.leaf || !(rootNode is CombinedNode cn))
            {
                return;
            }

            if (rootNode.type != QueryNodeType.Not)
            {
                return;
            }

            var parent  = rootNode.parent;
            var oldNode = rootNode.children[0];

            if (!(oldNode is CombinedNode oldCombinedNode) || (oldCombinedNode.type != QueryNodeType.And && oldCombinedNode.type != QueryNodeType.Or))
            {
                return;
            }

            CombinedNode newCombinedNode;

            if (oldNode.type == QueryNodeType.And)
            {
                newCombinedNode = new OrNode();
            }
            else
            {
                newCombinedNode = new AndNode();
            }

            cn.RemoveNode(oldNode);

            foreach (var child in oldNode.children)
            {
                var propagatedNotNode = new NotNode();
                propagatedNotNode.AddNode(child);
                newCombinedNode.AddNode(propagatedNotNode);
            }
            oldCombinedNode.Clear();

            // If the old not is the root of the evaluationGraph, then the new combined node
            // becomes the new root.
            if (parent == null)
            {
                this.root = newCombinedNode;
            }
            else
            {
                // In order to not change the parent's enumeration, swap directly the old
                // children with the new one
                SwapChild(parent, rootNode, newCombinedNode);
            }
            // Set the current tree root to the new combined node.
            rootNode = newCombinedNode;
        }
Пример #30
0
 public Type Visit(NotNode node)
 {
     if (Visit((dynamic)node[0]) != Type.BOOL)
     {
         throw new SemanticError(
                   $"Operator {node.AnchorToken.Lexeme} requires an operand of type {Type.BOOL}",
                   node.AnchorToken);
     }
     return(Type.BOOL);
 }
Пример #31
0
        public void Visit(NotNode n)
        {
            var children = n.GetChildren();

            foreach (var child in children)
            {
                child.SymTable = n.SymTable;
                child.Accept(this);
            }
        }
Пример #32
0
        private Node ConstructExpressionTree(List <Token> tokenList)
        {
            bool         flag   = false;
            Queue <Node> queue  = new Queue <Node>();
            Queue <Node> queue2 = new Queue <Node>();

            for (int i = 0; i < tokenList.Count; i++)
            {
                Token     token = tokenList[i];
                TokenKind kind  = token.Kind;
                if (kind == TokenKind.Identifier)
                {
                    Node item = new OperandNode(token.Text);
                    if (flag)
                    {
                        Node node2 = new NotNode {
                            Operand1 = item
                        };
                        flag = false;
                        queue.Enqueue(node2);
                    }
                    else
                    {
                        queue.Enqueue(item);
                    }
                }
                else if (kind == TokenKind.Not)
                {
                    flag = true;
                }
                else if ((kind != TokenKind.And) && (kind == TokenKind.Or))
                {
                    Node node3 = queue.Dequeue();
                    while (queue.Count > 0)
                    {
                        node3 = new AndNode(node3)
                        {
                            Operand1 = queue.Dequeue()
                        };
                    }
                    queue2.Enqueue(node3);
                }
            }
            Node n = queue2.Dequeue();

            while (queue2.Count > 0)
            {
                n = new OrNode(n)
                {
                    Operand1 = queue2.Dequeue()
                };
            }
            return(n);
        }
Пример #33
0
 public override void Exit(NotNode node)
 {
     this.ExitGroupNode(delegate(List <QueryFilter> currentFilters)
     {
         if (currentFilters.Count == 1)
         {
             return(new NotFilter(currentFilters[0]));
         }
         return(null);
     });
 }
Пример #34
0
 internal static NodeInfo Create(NotNode node)
 {
     return new NodeInfo(NodeType.Not, string.Empty);
 }