Example #1
0
    void Dispatcher::
    dispatch (SyntaxTree::NodePtr const& n)
    {
      LevelMap levels;

      unsigned long max = compute_levels (n->type_info (), 0, levels);

      //cerr << "starting dispatch process for "
      //     << n->type_info ().type_id () << " with "
      //     << max << " levels" << endl;

      for (unsigned long l = 0; l < max + 1; l++)
      {
        TypeInfoSet dispatched;

        for (LevelMap::const_iterator i = levels.begin ();
             i != levels.end ();
             i++)
        {
          if (i->second == l)
          {
            TraversalMap::const_iterator v =
              traversal_map_.find (i->first.type_id ());

            if (v != traversal_map_.end () && !(v->second.suppressed))
            {
              //cerr << "dispatching traverser for "
              //     << n->type_info ().type_id () << " as "
              //     << i->first.type_id () << endl;

              v->second.traverser->traverse (n);
              flatten_tree (i->first, dispatched);
            }
          }
        }

        // Remove traversed types from level map.
        for (TypeInfoSet::const_iterator i = dispatched.begin ();
             i != dispatched.end ();
             i++)
        {
          levels.erase (*i);
        }
      }
    }
  void Dispatcher::
  dispatch (SyntaxTree::Node* n)
  {
    LevelMap levels;

    unsigned long max = compute_levels (n->type_info (), 0, levels);

    for (unsigned long l = 0; l < max + 1; l++)
    {
      TypeInfoSet dispatched;

      for (LevelMap::const_iterator i = levels.begin ();
           i != levels.end ();
           i++)
      {
        if (i->second == l)
        {
          TraversalMap::const_iterator v =
            traversal_map_.find (i->first.type_id ());

          if (v != traversal_map_.end ())
          {
            v->second->traverse (n);
            flatten_tree (i->first, dispatched);
          }
        }
      }

      // Remove traversed types from level map.
      for (TypeInfoSet::const_iterator i = dispatched.begin ();
           i != dispatched.end ();
           i++)
      {
        levels.erase (*i);
      }
    }
  }