1 // sequence_node.hpp 2 // Copyright (c) 2007-2009 Ben Hanson (http://www.benhanson.net/) 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 #ifndef BOOST_SPIRIT_SUPPORT_DETAIL_LEXER_PARSER_TREE_SEQUENCE_NODE_HPP 7 #define BOOST_SPIRIT_SUPPORT_DETAIL_LEXER_PARSER_TREE_SEQUENCE_NODE_HPP 8 9 #include "node.hpp" 10 11 namespace boost 12 { 13 namespace lexer 14 { 15 namespace detail 16 { 17 class sequence_node : public node 18 { 19 public: sequence_node(node * left_,node * right_)20 sequence_node (node *left_, node *right_) : 21 node (left_->nullable () && right_->nullable ()), 22 _left (left_), 23 _right (right_) 24 { 25 _left->append_firstpos (_firstpos); 26 27 if (_left->nullable ()) 28 { 29 _right->append_firstpos (_firstpos); 30 } 31 32 if (_right->nullable ()) 33 { 34 _left->append_lastpos (_lastpos); 35 } 36 37 _right->append_lastpos (_lastpos); 38 39 node_vector &lastpos_ = _left->lastpos (); 40 const node_vector &firstpos_ = _right->firstpos (); 41 42 for (node_vector::iterator iter_ = lastpos_.begin (), 43 end_ = lastpos_.end (); iter_ != end_; ++iter_) 44 { 45 (*iter_)->append_followpos (firstpos_); 46 } 47 } 48 ~sequence_node()49 virtual ~sequence_node () 50 { 51 } 52 what_type() const53 virtual type what_type () const 54 { 55 return SEQUENCE; 56 } 57 traverse(const_node_stack & node_stack_,bool_stack & perform_op_stack_) const58 virtual bool traverse (const_node_stack &node_stack_, 59 bool_stack &perform_op_stack_) const 60 { 61 perform_op_stack_.push (true); 62 63 switch (_right->what_type ()) 64 { 65 case SEQUENCE: 66 case SELECTION: 67 case ITERATION: 68 perform_op_stack_.push (false); 69 break; 70 default: 71 break; 72 } 73 74 node_stack_.push (_right); 75 node_stack_.push (_left); 76 return true; 77 } 78 79 private: 80 // Not owner of these pointers... 81 node *_left; 82 node *_right; 83 copy_node(node_ptr_vector & node_ptr_vector_,node_stack & new_node_stack_,bool_stack & perform_op_stack_,bool & down_) const84 virtual void copy_node (node_ptr_vector &node_ptr_vector_, 85 node_stack &new_node_stack_, bool_stack &perform_op_stack_, 86 bool &down_) const 87 { 88 if (perform_op_stack_.top ()) 89 { 90 node *rhs_ = new_node_stack_.top (); 91 92 new_node_stack_.pop (); 93 94 node *lhs_ = new_node_stack_.top (); 95 96 node_ptr_vector_->push_back (static_cast<sequence_node *>(0)); 97 node_ptr_vector_->back () = new sequence_node (lhs_, rhs_); 98 new_node_stack_.top () = node_ptr_vector_->back (); 99 } 100 else 101 { 102 down_ = true; 103 } 104 105 perform_op_stack_.pop (); 106 } 107 }; 108 } 109 } 110 } 111 112 #endif 113