Esempio n. 1
0
        protected override void Visit(SpecialNode specialNode)
        {
            string name = NameUtility.GetName(specialNode.Element.Name);

            if (!this.SpecialNodeMap.ContainsKey(name))
            {
                throw new CompilerException(string.Format("Unknown special node {0}", specialNode.Element.Name));
            }
            Action <SpecialNode, SpecialNodeInspector> action = this.SpecialNodeMap[name];

            action(specialNode, new SpecialNodeInspector(specialNode));
        }
Esempio n. 2
0
        private void VisitUnless(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var conditionAttr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("unless");

            var unlessChunk = new ConditionalChunk {
                Type = ConditionalType.Unless, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode)
            };

            Chunks.Add(unlessChunk);
            using (new Frame(this, unlessChunk.Body))
                Accept(specialNode.Body);
        }
Esempio n. 3
0
        private void VisitGlobal(SpecialNode specialNode)
        {
            var typeAttr = specialNode.Element.Attributes.FirstOrDefault(attr => attr.Name == "type");
            var type     = typeAttr != null?AsCode(typeAttr) : (Snippets)"object";

            foreach (var attr in specialNode.Element.Attributes.Where(a => a != typeAttr))
            {
                AddUnordered(new GlobalVariableChunk {
                    Type = type, Name = attr.Name, Value = AsTextOrientedCode(attr)
                });
            }
        }
Esempio n. 4
0
        public void VisitNode(INodeVisitor visitor, IList <Node> body, IList <Chunk> chunks)
        {
            var registerTarget = string.Format(
                @"RegisterTarget(""{0}"", ""{1}"", ""{2}"", __target_{3});",
                _idAttribute.Value,
                _classAttribute != null ? _classAttribute.Value : "",
                _descriptionAttribute != null ? _descriptionAttribute.Value : "",
                _targetExtensionCount);

            if (_targetAttribute != null)
            {
                registerTarget +=
                    Environment.NewLine +
                    string.Format(
                        @"RegisterTarget(""{0}"", ""{1}"", null, null);",
                        _targetAttribute.Value,
                        _idAttribute.Value);
            }

            var beginLambda = string.Format(
                @"__target_{0} = () => {{",
                _targetExtensionCount);
            const string endLambda = "};";

            var startingTarget = string.Format(
                @"StartingTarget(""{0}"");",
                _idAttribute.Value);

            var nameAttribute = new AttributeNode("name", _idAttribute.QuotChar, _idAttribute.Nodes)
            {
                OriginalNode = _idAttribute
            };

            var macroAttributes = _targetElement.Attributes
                                  .Where(x => x != _idAttribute && x != _classAttribute && x != _descriptionAttribute)
                                  .Concat(new[] { nameAttribute })
                                  .ToList();
            var macroElement = new SpecialNode(new ElementNode("macro", macroAttributes, false));

            var onceAttribute = new AttributeNode("once", _idAttribute.QuotChar, _idAttribute.Nodes);
            var testElement   = new SpecialNode(new ElementNode("test", new[] { onceAttribute }, false));


            macroElement.Body.Add(testElement);
            testElement.Body = body;
            testElement.Body.Insert(0, new StatementNode(startingTarget));

            visitor.Accept(new StatementNode(beginLambda));
            visitor.Accept(testElement);
            visitor.Accept(new StatementNode(endLambda));
            visitor.Accept(new StatementNode(registerTarget));
        }
        protected override void Visit(SpecialNode specialNode)
        {
            string name = NameUtility.GetName(specialNode.Element.Name);

            if (!string.IsNullOrEmpty(specialNode.Element.PreceedingWhitespace) &&
                this.specialNodeMap.ContainsKey(name))
            {
                var action = this.specialNodeMap[name];
                action(specialNode, new SpecialNodeInspector(specialNode));
            }

            base.Visit(specialNode);
        }
Esempio n. 6
0
        private void VisitUnless(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            AttributeNode    attr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("unless");
            ConditionalChunk item = new ConditionalChunk {
                Type      = ConditionalType.Unless,
                Condition = this.AsCode(attr),
                Position  = this.Locate(inspector.OriginalNode)
            };

            this.Chunks.Add(item);
            using (new Frame(this, item.Body))
            {
                base.Accept(specialNode.Body);
            }
        }
Esempio n. 7
0
 protected void VisitIf(SpecialNode specialNode, SpecialNodeInspector inspector)
 {
     if (!this.FirstChildBeginsWithNewline(specialNode))
     {
         List <Node> list = new List <Node> {
             new TextNode(specialNode.Element.PreceedingWhitespace)
         };
         if (specialNode.Body != null)
         {
             list.AddRange(specialNode.Body);
         }
         specialNode.Body = list;
     }
     specialNode.Element.PreceedingWhitespace = string.Empty;
 }
Esempio n. 8
0
        protected override void Visit(SpecialNode specialNode)
        {
            var inspector = new SpecialNodeInspector(specialNode);

            if (inspector.Name == "use")
            {
                var file = inspector.TakeAttribute("file");
                if (file != null)
                {
                    References.Add(new FileReference { File = file.Value, UseFileNode = specialNode });
                }
            }

            Accept(specialNode.Body);
        }
Esempio n. 9
0
 public LinkedNodeList()
 {
     head                = new SpecialNode();
     head.prev           = new SpecialNode();
     head.prev.name      = "";
     head.path           = "€";
     head.name           = parents[parentIndex++];
     head.selfLoopPS     = string.Empty;
     head.targetLoopPS   = string.Empty;
     head.targetLoopName = string.Empty;
     head.next           = new List <SpecialNode>();
     NCGG                = new NodeChart();
     lastStates          = new List <string>();
     current             = head;
 }
Esempio n. 10
0
        /// <summary>
        /// The decode nas list.
        /// </summary>
        /// <param name="asnCode">
        /// The asn code.
        /// </param>
        /// <param name="speValue">
        /// The spe value.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string DecodeNasList(string asnCode, SpecialNode speValue)
        {
            var nasList    = this.GetNasList(asnCode, speValue.DecodePort);
            var nasDecoder = this.GetDecoder(speValue.DecodeDll);

            foreach (var nasStream in nasList)
            {
                var stream    = this.DecodeByteStream(nasStream, nasDecoder, speValue.DecodePdu);
                var nasString = "(需二次解析码流)" + nasStream;
                asnCode = asnCode.Replace(nasStream, nasString);
                asnCode = asnCode + '\n' + stream;
            }

            return(asnCode);
        }
Esempio n. 11
0
        private void VisitElseIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            if (!SatisfyElsePrecondition())
            {
                throw new CompilerException("An 'elseif' may only follow an 'if' or 'elseif'.");
            }

            var conditionAttr = inspector.TakeAttribute("condition");
            var elseIfChunk   = new ConditionalChunk {
                Type = ConditionalType.ElseIf, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode)
            };

            Chunks.Add(elseIfChunk);
            using (new Frame(this, elseIfChunk.Body))
                Accept(specialNode.Body);
        }
Esempio n. 12
0
        public void Fill_in_argument_by_type_with_ObjectFactory()
        {
            ObjectFactory.Initialize(x => { x.For <IView>().Use <View>(); });

            var theNode  = new SpecialNode();
            var theTrade = new Trade();

            var command = ObjectFactory.Container
                          .With(typeof(Node), theNode)
                          .With(theTrade)
                          .GetInstance <Command>();

            command.View.ShouldBeOfType <View>();
            theNode.ShouldBeTheSameAs(command.Node);
            theTrade.ShouldBeTheSameAs(command.Trade);
        }
Esempio n. 13
0
    SpecialNode CreateTailNode(int x, int y)
    {
        SpecialNode spNode = new SpecialNode();

        spNode.node = GetNode(x, y);
        spNode.obj  = new GameObject();
        spNode.obj.transform.parent     = tailParent.transform;
        spNode.obj.transform.position   = spNode.node.worldPosition;
        spNode.obj.transform.localScale = Vector3.one * .95f;
        SpriteRenderer renderer = spNode.obj.AddComponent <SpriteRenderer>();

        renderer.sprite       = playerSprite;
        renderer.sortingOrder = 1;

        return(spNode);
    }
Esempio n. 14
0
        protected void VisitIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            if (!FirstChildBeginsWithNewline(specialNode))
            {
                var newBody = new List <Node>();
                newBody.Add(new TextNode(specialNode.Element.PreceedingWhitespace));
                if (specialNode.Body != null)
                {
                    newBody.AddRange(specialNode.Body);
                }

                specialNode.Body = newBody;
            }

            specialNode.Element.PreceedingWhitespace = string.Empty;
        }
Esempio n. 15
0
        public void Fill_in_argument_by_type_with_Container()
        {
            var container = new Container(x => x.For <IView>().Use <View>());

            var theNode  = new SpecialNode();
            var theTrade = new Trade();

            var command = container
                          .With(typeof(Node), theNode)
                          .With(theTrade)
                          .GetInstance <Command>();

            command.View.ShouldBeOfType <View>();
            theNode.ShouldBeTheSameAs(command.Node);
            theTrade.ShouldBeTheSameAs(command.Trade);
        }
        public void Fill_in_argument_by_type()
        {
            var container = new Container(x => { x.ForRequestedType <IView>().TheDefaultIsConcreteType <View>(); });

            var theNode  = new SpecialNode();
            var theTrade = new Trade();

            var command = container
                          .With(typeof(Node), theNode)
                          .With(theTrade)
                          .GetInstance <Command>();

            Assert.IsInstanceOfType(typeof(View), command.View);
            Assert.AreSame(theNode, command.Node);
            Assert.AreSame(theTrade, command.Trade);
        }
        public void Fill_in_argument_by_type_with_ObjectFactory()
        {
            ObjectFactory.Initialize(x => { x.ForRequestedType <IView>().TheDefaultIsConcreteType <View>(); });

            var theNode  = new SpecialNode();
            var theTrade = new Trade();

            var command = ObjectFactory
                          .With(typeof(Node), theNode)
                          .With(theTrade)
                          .GetInstance <Command>();

            Assert.IsInstanceOfType(typeof(View), command.View);
            Assert.AreSame(theNode, command.Node);
            Assert.AreSame(theTrade, command.Trade);
        }
Esempio n. 18
0
        private void VisitGlobal(SpecialNode specialNode)
        {
            AttributeNode typeAttr = specialNode.Element.Attributes.FirstOrDefault <AttributeNode>(attr => attr.Name == "type");
            Snippets      snippets = (typeAttr != null) ? this.AsCode(typeAttr) : "object";

            foreach (AttributeNode node in from a in specialNode.Element.Attributes
                     where a != typeAttr
                     select a)
            {
                GlobalVariableChunk chunk = new GlobalVariableChunk {
                    Type  = snippets,
                    Name  = node.Name,
                    Value = this.AsTextOrientedCode(node)
                };
                this.AddUnordered(chunk);
            }
        }
Esempio n. 19
0
        protected override void Visit(SpecialNode specialNode)
        {
            var inspector = new SpecialNodeInspector(specialNode);

            if (inspector.Name == "use")
            {
                var file = inspector.TakeAttribute("file");
                if (file != null)
                {
                    References.Add(new FileReference {
                        File = file.Value, UseFileNode = specialNode
                    });
                }
            }

            Accept(specialNode.Body);
        }
Esempio n. 20
0
        private void VisitIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var conditionAttr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("if");

            var onceAttr = inspector.TakeAttribute("once");

            if (conditionAttr == null && onceAttr == null)
            {
                throw new CompilerException("Element must contain an if, condition, or once attribute");
            }

            Frame ifFrame = null;

            if (conditionAttr != null)
            {
                var ifChunk = new ConditionalChunk {
                    Type = ConditionalType.If, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(ifChunk);
                ifFrame = new Frame(this, ifChunk.Body);
            }

            Frame onceFrame = null;

            if (onceAttr != null)
            {
                var onceChunk = new ConditionalChunk {
                    Type = ConditionalType.Once, Condition = onceAttr.AsCodeInverted(), Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(onceChunk);
                onceFrame = new Frame(this, onceChunk.Body);
            }

            Accept(specialNode.Body);

            if (onceFrame != null)
            {
                onceFrame.Dispose();
            }

            if (ifFrame != null)
            {
                ifFrame.Dispose();
            }
        }
        private void PopSpecial(string name)
        {
            if (this._stack.Count == 0)
            {
                throw new CompilerException(string.Format("Unexpected end element {0}", name));
            }
            this._nodes = this._stack.Pop();
            SpecialNode node = this.Nodes.Last <Node>() as SpecialNode;

            if (node == null)
            {
                throw new CompilerException(string.Format("Unexpected end element {0}", name));
            }
            if (node.Element.Name != name)
            {
                throw new CompilerException(string.Format("End element {0} did not match {1}", name, node.Element.Name));
            }
        }
Esempio n. 22
0
        private void VisitElseIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            if (!this.SatisfyElsePrecondition())
            {
                throw new CompilerException("An 'elseif' may only follow an 'if' or 'elseif'.");
            }
            AttributeNode    attr = inspector.TakeAttribute("condition");
            ConditionalChunk item = new ConditionalChunk {
                Type      = ConditionalType.ElseIf,
                Condition = this.AsCode(attr),
                Position  = this.Locate(inspector.OriginalNode)
            };

            this.Chunks.Add(item);
            using (new Frame(this, item.Body))
            {
                base.Accept(specialNode.Body);
            }
        }
Esempio n. 23
0
        private void VisitIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            AttributeNode attr  = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("if");
            AttributeNode node2 = inspector.TakeAttribute("once");

            if ((attr == null) && (node2 == null))
            {
                throw new CompilerException("Element must contain an if, condition, or once attribute");
            }
            Frame frame = null;

            if (attr != null)
            {
                ConditionalChunk item = new ConditionalChunk {
                    Type      = ConditionalType.If,
                    Condition = this.AsCode(attr),
                    Position  = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(item);
                frame = new Frame(this, item.Body);
            }
            Frame frame2 = null;

            if (node2 != null)
            {
                ConditionalChunk chunk3 = new ConditionalChunk {
                    Type      = ConditionalType.Once,
                    Condition = node2.AsCodeInverted(),
                    Position  = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(chunk3);
                frame2 = new Frame(this, chunk3.Body);
            }
            base.Accept(specialNode.Body);
            if (frame2 != null)
            {
                frame2.Dispose();
            }
            if (frame != null)
            {
                frame.Dispose();
            }
        }
Esempio n. 24
0
        private bool FirstChildBeginsWithNewline(SpecialNode node)
        {
            if (node == null ||
                node.Body == null ||
                node.Body.Count == 0)
            {
                return(false);
            }

            var firstChild = node.Body[0];

            if (firstChild == null)
            {
                return(false);
            }

            var textNode = firstChild as TextNode;

            if (textNode != null)
            {
                return(textNode.Text.IndexOf("\r\n") == 0 ||
                       textNode.Text.IndexOf("\n") == 0);
            }

            var elementNode = firstChild as ElementNode;

            if (elementNode == null)
            {
                var specialNode = firstChild as SpecialNode;
                if (specialNode != null)
                {
                    elementNode = specialNode.Element;
                }
            }

            if (elementNode != null)
            {
                return(elementNode.PreceedingWhitespace.IndexOf("\r\n") == 0 ||
                       elementNode.PreceedingWhitespace.IndexOf("\n") == 0);
            }

            return(false);
        }
Esempio n. 25
0
        private bool FirstChildBeginsWithNewline(SpecialNode node)
        {
            if (((node == null) || (node.Body == null)) || (node.Body.Count == 0))
            {
                return(false);
            }
            Node node2 = node.Body[0];

            if (node2 == null)
            {
                return(false);
            }
            TextNode node3 = node2 as TextNode;

            if (node3 != null)
            {
                if (node3.Text.IndexOf("\r\n") != 0)
                {
                    return(node3.Text.IndexOf("\n") == 0);
                }
                return(true);
            }
            ElementNode element = node2 as ElementNode;

            if (element == null)
            {
                SpecialNode node5 = node2 as SpecialNode;
                if (node5 != null)
                {
                    element = node5.Element;
                }
            }
            if (element == null)
            {
                return(false);
            }
            if (element.PreceedingWhitespace.IndexOf("\r\n") != 0)
            {
                return(element.PreceedingWhitespace.IndexOf("\n") == 0);
            }
            return(true);
        }
Esempio n. 26
0
        private void PopSpecial(string name)
        {
            if (_stack.Count == 0)
            {
                throw new CompilerException(string.Format("Unexpected end element {0}", name));
            }

            _nodes = _stack.Pop();
            SpecialNode special = Nodes.Last() as SpecialNode;

            if (special == null)
            {
                throw new CompilerException(string.Format("Unexpected end element {0}", name));
            }

            if (special.Element.Name != name)
            {
                throw new CompilerException(string.Format("End element {0} did not match {1}", name, special.Element.Name));
            }
        }
Esempio n. 27
0
        private void VisitCache(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var keyAttr     = inspector.TakeAttribute("key");
            var expiresAttr = inspector.TakeAttribute("expires");
            var signalAttr  = inspector.TakeAttribute("signal");

            var chunk = new CacheChunk {
                Position = Locate(specialNode.Element)
            };

            if (keyAttr != null)
            {
                chunk.Key = AsCode(keyAttr);
            }
            else
            {
                chunk.Key = "\"\"";
            }

            if (expiresAttr != null)
            {
                chunk.Expires = AsCode(expiresAttr);
            }
            else
            {
                chunk.Expires = "";
            }

            if (signalAttr != null)
            {
                chunk.Signal = AsCode(signalAttr);
            }
            else
            {
                chunk.Signal = "";
            }

            Chunks.Add(chunk);
            using (new Frame(this, chunk.Body))
                Accept(inspector.Body);
        }
Esempio n. 28
0
            public void AddChild(SpecialNode n, bool gotoNext)
            {
                if (gotoNext)
                {
                    current.next.Add(n);
                    if (current == head)
                    {
                        current = current.next[Yrow];
                    }
                    else
                    {
                        current = current.next[0];
                    }
                    current.next = new List <SpecialNode>();
                }
                else
                {
                    current.next.Add(n);
                    if (current == head)
                    {
                        current = current.next[Yrow];
                    }
                    else
                    {
                        current = current.next[0];
                    }

                    SpecialNode garbageNode = new SpecialNode();
                    garbageNode.name           = parents[parentIndex++];
                    garbageNode.next           = null;
                    garbageNode.prev           = current;
                    garbageNode.path           = "€";
                    garbageNode.targetLoopName = string.Empty;
                    garbageNode.targetLoopPS   = string.Empty;
                    garbageNode.selfLoopPS     = "";
                    garbageNode.isFinal        = false;
                    current.next = new List <SpecialNode>();
                    current.next.Add(garbageNode);
                    lastStates.Add(garbageNode.name);
                }
            }
Esempio n. 29
0
        protected override void Visit(ExtensionNode node)
        {
            ExtensionNode item  = new ExtensionNode(node.Element, node.Extension);
            AttributeNode node3 = item.Element.Attributes.FirstOrDefault <AttributeNode>(attr => this.IsSpecialAttribute(node.Element, attr));

            if (node3 != null)
            {
                SpecialNode node4 = this.CreateWrappingNode(node3, item.Element);
                item.Element.Attributes.Remove(node3);
                this.Nodes.Add(node4);
                base.PushFrame(node4.Body, new Frame());
            }
            this.Nodes.Add(item);
            base.PushFrame(item.Body, new Frame());
            base.Accept(node.Body);
            base.PopFrame();
            if (node3 != null)
            {
                base.PopFrame();
            }
        }
Esempio n. 30
0
        private void VisitFor(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var eachAttr = inspector.TakeAttribute("each");

            var forEachChunk = new ForEachChunk {
                Code = AsCode(eachAttr), Position = Locate(specialNode.Element)
            };

            Chunks.Add(forEachChunk);
            using (new Frame(this, forEachChunk.Body))
            {
                foreach (var attr in inspector.Attributes)
                {
                    Chunks.Add(new AssignVariableChunk {
                        Name = attr.Name, Value = AsCode(attr), Position = Locate(attr)
                    });
                }

                Accept(specialNode.Body);
            }
        }
        private TreeNode CreateNode(SpecialNode specialNode)
        {
            var treeNode = new TreeNode();

            treeNode.Tag = specialNode;
            switch (specialNode)
            {
            case SpecialNode.DummyNode:
                treeNode.Text = "Dummy";
                break;

            case SpecialNode.DirectCopiesRecursive:
                treeNode.Text = "Direct copies (recursive)";
                break;

            case SpecialNode.DirectCopies:
                treeNode.Text = "Direct copies";
                break;

            case SpecialNode.Reads:
                treeNode.Text = "Other variables in operations reading this variable";
                break;

            case SpecialNode.Writes:
                treeNode.Text = "Other variables in operations writing to this variable";
                break;

            default:
                treeNode.Text = "Invalid Node";
                specialNode   = SpecialNode.Invalid;
                treeNode.Tag  = specialNode;
                break;
            }
            if (specialNode != SpecialNode.DummyNode && specialNode != SpecialNode.Invalid)
            {
                treeNode.Nodes.Add(CreateNode(SpecialNode.DummyNode));
            }
            return(treeNode);
        }
        public void Fill_in_argument_by_type_with_ObjectFactory()
        {
            ObjectFactory.Initialize(x => { x.For<IView>().Use<View>(); });

            var theNode = new SpecialNode();
            var theTrade = new Trade();

            var command = ObjectFactory.Container
                .With(typeof (Node), theNode)
                .With(theTrade)
                .GetInstance<Command>();

            command.View.ShouldBeOfType<View>();
            theNode.ShouldBeTheSameAs(command.Node);
            theTrade.ShouldBeTheSameAs(command.Trade);
        }
        public void Fill_in_argument_by_type()
        {
            var container = new Container(x => { x.For<IView>().Use<View>(); });

            var theNode = new SpecialNode();
            var theTrade = new Trade();

            var command = container
                .With(typeof (Node), theNode)
                .With(theTrade)
                .GetInstance<Command>();

            command.View.ShouldBeOfType<View>();
            theNode.ShouldBeTheSameAs(command.Node);
            theTrade.ShouldBeTheSameAs(command.Trade);
        }
Esempio n. 34
0
        public void Fill_in_argument_by_type()
        {
            var container = new Container(x => { x.ForRequestedType<IView>().TheDefaultIsConcreteType<View>(); });

            var theNode = new SpecialNode();
            var theTrade = new Trade();

            var command = container
                .With(typeof (Node), theNode)
                .With(theTrade)
                .GetInstance<Command>();

            Assert.IsInstanceOfType(typeof (View), command.View);
            Assert.AreSame(theNode, command.Node);
            Assert.AreSame(theTrade, command.Trade);
        }
Esempio n. 35
0
        public void Fill_in_argument_by_type_with_ObjectFactory()
        {
            ObjectFactory.Initialize(x => { x.ForRequestedType<IView>().TheDefaultIsConcreteType<View>(); });

            var theNode = new SpecialNode();
            var theTrade = new Trade();

            var command = ObjectFactory
                .With(typeof (Node), theNode)
                .With(theTrade)
                .GetInstance<Command>();

            Assert.IsInstanceOfType(typeof (View), command.View);
            Assert.AreSame(theNode, command.Node);
            Assert.AreSame(theTrade, command.Trade);
        }