Пример #1
0
        private void CEVariable(Parse.Variable Item, Parse.Block Parent, Block Compiled)
        {
            switch (Item.Type)
            {
            case Parse.Variable.eType.Variable:
                var var_index = Parent.Function.Variables[Item.Name];
                var nfv       = new NodeFromVariable(var_index);
                nfv.Name = Item.Name;
                //Get the inital node
                Compiled.AddItem(nfv);
                break;

            case Parse.Variable.eType.RetVal:
                //Get the inital node
                Compiled.AddItem(new NodeFromRetVal());
                break;

            case Parse.Variable.eType.Tree:
                //Get the inital node
                Compiled.AddItem(new NodeFromTree());
                break;

            case Parse.Variable.eType.Skipped:
                //Put Skipped at LastResult
                Compiled.AddItem(new SkippedToResult());
                break;

            case Parse.Variable.eType.Source:
                //Put Source at LastResult
                Compiled.AddItem(new SourceToResult());
                break;

            case Parse.Variable.eType.New:
                //Create a new TreeRoot
                Compiled.AddItem(new NodeFromNew());
                break;

            case Parse.Variable.eType.Setting:
                ThrowParseError("Settings not supported", Item.Annotation.SourcePosition);
                break;

            default:
                ThrowParseError("Unknown type", Item.Annotation.SourcePosition);
                break;
            }

            //Get the nodes
            if (Item.Nodes.Count > 0)
            {
                //Clear any temps that are left
                var ptc = new PushTemporariesCount();
                Compiled.AddItem(ptc);

                //Check to see if actualy a temp guard is needed
                bool temp_guard_is_needed = false;

                foreach (var tn in Item.Nodes)
                {
                    switch (tn.Type)
                    {
                    case Parse.TreeNode.eType.Normal:
                        if (!(tn.Key is Parse.Literal))
                        {
                            temp_guard_is_needed = true;
                        }
                        //Push Result to Temp
                        Compiled.AddItem(new ResultToTemp());
                        //Get the key
                        CompileElement(tn.Key, Parent, Compiled);
                        //Get the node
                        Compiled.AddItem(new NodeByName(tn.Index, false, tn.Index != -1));
                        //Search by Value
                        if (tn.Value != null)
                        {
                            if (!(tn.Value is Parse.Literal))
                            {
                                temp_guard_is_needed = true;
                            }
                            //Push Result to Temp
                            Compiled.AddItem(new ResultToTemp());
                            //Get the value
                            CompileElement(tn.Value, Parent, Compiled);
                            //Get the node
                            Compiled.AddItem(new NodeSiblingByValue(tn.ByValueNext, tn.ByValueIgnoreCase));
                        }
                        break;

                    case Parse.TreeNode.eType.Indexed:
                        //Search by Value
                        if (tn.Value != null)
                        {
                            if (!(tn.Value is Parse.Literal))
                            {
                                temp_guard_is_needed = true;
                            }
                            //Push Result to Temp
                            Compiled.AddItem(new ResultToTemp());
                            //Get the value
                            CompileElement(tn.Value, Parent, Compiled);
                            //Get the node
                            Compiled.AddItem(new NodeSiblingByValue(tn.ByValueNext, tn.ByValueIgnoreCase));
                        }
                        else                         //Get by index
                                                     //Get the node
                        {
                            Compiled.AddItem(new NodeSiblingByIndex(tn.Index));
                        }
                        break;

                    case Parse.TreeNode.eType.New:
                        if (tn.Key == null)
                        {
                            //Get a new node
                            Compiled.AddItem(new NodeSiblingNew());
                        }
                        else
                        {
                            if (!(tn.Key is Parse.Literal))
                            {
                                temp_guard_is_needed = true;
                            }
                            //Push Result to Temp
                            Compiled.AddItem(new ResultToTemp());
                            //Get the key
                            CompileElement(tn.Key, Parent, Compiled);
                            //Get the node
                            Compiled.AddItem(new NodeByName(tn.Index, true, false));
                        }
                        break;

                    case Parse.TreeNode.eType.NotNew:
                        if (!(tn.Key is Parse.Literal))
                        {
                            temp_guard_is_needed = true;
                        }
                        //Push Result to Temp
                        Compiled.AddItem(new ResultToTemp());
                        //Get the key
                        CompileElement(tn.Key, Parent, Compiled);
                        //Get the node
                        Compiled.AddItem(new NodeByName(tn.Index, false, true));
                        break;

                    case Parse.TreeNode.eType.Parent:
                        //Get the node
                        Compiled.AddItem(new NodeParent());
                        break;

                    case Parse.TreeNode.eType.Next:
                        //Get the node
                        Compiled.AddItem(new NodeSiblingByNeighbour(true));
                        break;

                    case Parse.TreeNode.eType.Previous:
                        //Get the node
                        Compiled.AddItem(new NodeSiblingByNeighbour(false));
                        break;

                    case Parse.TreeNode.eType.Value:
                        //Get the text
                        Compiled.AddItem(new NodeValue());
                        break;

                    case Parse.TreeNode.eType.Name:
                        //Get the name
                        Compiled.AddItem(new NodeName());
                        break;

                    default:
                        ThrowParseError("Unknown tree type", Item.Annotation.SourcePosition);
                        break;
                    }
                }

                if (temp_guard_is_needed)
                {
                    //Clear any temps that are left
                    Compiled.AddItem(new PopClearTemporaries());
                }
                else
                {
                    Compiled.RemoveItem(ptc);
                }
            }
        }
        private void CEVariable(Parse.Variable Item, Parse.Block Parent, Block Compiled)
        {
            switch (Item.Type)
            {
            case Parse.Variable.eType.Variable:
                var var_index = Parent.Function.Variables[Item.Name];
                var nfv = new NodeFromVariable(var_index);
                nfv.Name = Item.Name;
                //Get the inital node
                Compiled.AddItem(nfv);
                break;
            case Parse.Variable.eType.RetVal:
                //Get the inital node
                Compiled.AddItem(new NodeFromRetVal());
                break;
            case Parse.Variable.eType.Tree:
                //Get the inital node
                Compiled.AddItem(new NodeFromTree());
                break;
            case Parse.Variable.eType.Skipped:
                //Put Skipped at LastResult
                Compiled.AddItem(new SkippedToResult());
                break;
            case Parse.Variable.eType.Source:
                //Put Source at LastResult
                Compiled.AddItem(new SourceToResult());
                break;
            case Parse.Variable.eType.New:
                //Create a new TreeRoot
                Compiled.AddItem(new NodeFromNew());
                break;
            case Parse.Variable.eType.Setting:
                ThrowParseError("Settings not supported", Item.Annotation.SourcePosition);
                break;
            default:
                ThrowParseError("Unknown type", Item.Annotation.SourcePosition);
                break;
            }

            //Get the nodes
            if (Item.Nodes.Count > 0)
            {
                //Clear any temps that are left
                var ptc = new PushTemporariesCount();
                Compiled.AddItem(ptc);

                //Check to see if actualy a temp guard is needed
                bool temp_guard_is_needed = false;

                foreach (var tn in Item.Nodes)
                {
                    switch (tn.Type)
                    {
                    case Parse.TreeNode.eType.Normal:
                        if (!(tn.Key is Parse.Literal))
                            temp_guard_is_needed = true;
                        //Push Result to Temp
                        Compiled.AddItem(new ResultToTemp());
                        //Get the key
                        CompileElement(tn.Key, Parent, Compiled);
                        //Get the node
                        Compiled.AddItem(new NodeByName(tn.Index, false, tn.Index != -1));
                        //Search by Value
                        if (tn.Value != null)
                        {
                            if (!(tn.Value is Parse.Literal))
                                temp_guard_is_needed = true;
                            //Push Result to Temp
                            Compiled.AddItem(new ResultToTemp());
                            //Get the value
                            CompileElement(tn.Value, Parent, Compiled);
                            //Get the node
                            Compiled.AddItem(new NodeSiblingByValue(tn.ByValueNext, tn.ByValueIgnoreCase));
                        }
                        break;
                    case Parse.TreeNode.eType.Indexed:
                        //Search by Value
                        if (tn.Value != null)
                        {
                            if (!(tn.Value is Parse.Literal))
                                temp_guard_is_needed = true;
                            //Push Result to Temp
                            Compiled.AddItem(new ResultToTemp());
                            //Get the value
                            CompileElement(tn.Value, Parent, Compiled);
                            //Get the node
                            Compiled.AddItem(new NodeSiblingByValue(tn.ByValueNext, tn.ByValueIgnoreCase));
                        }
                        else //Get by index
                            //Get the node
                            Compiled.AddItem(new NodeSiblingByIndex(tn.Index));
                        break;
                    case Parse.TreeNode.eType.New:
                        if (tn.Key == null)
                            //Get a new node
                            Compiled.AddItem(new NodeSiblingNew());
                        else
                        {
                            if (!(tn.Key is Parse.Literal))
                                temp_guard_is_needed = true;
                            //Push Result to Temp
                            Compiled.AddItem(new ResultToTemp());
                            //Get the key
                            CompileElement(tn.Key, Parent, Compiled);
                            //Get the node
                            Compiled.AddItem(new NodeByName(tn.Index, true, false));
                        }
                        break;
                    case Parse.TreeNode.eType.NotNew:
                        if (!(tn.Key is Parse.Literal))
                            temp_guard_is_needed = true;
                        //Push Result to Temp
                        Compiled.AddItem(new ResultToTemp());
                        //Get the key
                        CompileElement(tn.Key, Parent, Compiled);
                        //Get the node
                        Compiled.AddItem(new NodeByName(tn.Index, false, true));
                        break;
                    case Parse.TreeNode.eType.Parent:
                        //Get the node
                        Compiled.AddItem(new NodeParent());
                        break;
                    case Parse.TreeNode.eType.Next:
                        //Get the node
                        Compiled.AddItem(new NodeSiblingByNeighbour(true));
                        break;
                    case Parse.TreeNode.eType.Previous:
                        //Get the node
                        Compiled.AddItem(new NodeSiblingByNeighbour(false));
                        break;
                    case Parse.TreeNode.eType.Value:
                        //Get the text
                        Compiled.AddItem(new NodeValue());
                        break;
                    case Parse.TreeNode.eType.Name:
                        //Get the name
                        Compiled.AddItem(new NodeName());
                        break;
                    default:
                        ThrowParseError("Unknown tree type", Item.Annotation.SourcePosition);
                        break;
                    }
                }

                if (temp_guard_is_needed)
                    //Clear any temps that are left
                    Compiled.AddItem(new PopClearTemporaries());
                else
                    Compiled.RemoveItem(ptc);
            }
        }