1 // file : XSCRT/Traversal.tpp
2 // author : Boris Kolpackov <boris@dre.vanderbilt.edu>
8 //@@ merge after dropping VC6
10 void DispatcherBase<B>::
16 ExtendedTypeInfo const& ti = extended_type_info (n);
18 unsigned long max = compute_levels (ti, 0, levels);
21 //wcerr << "starting dispatch process for "
22 // << typeid (n).name () << " with "
23 // << max << " levels" << endl;
25 for (unsigned long l = 0; l < max + 1; ++l)
27 TypeInfoSet dispatched;
29 for (typename LevelMap::const_iterator
30 i (levels.begin ()), e (levels.end ());
35 typename TraversalMap::const_iterator v (
36 traversal_map_.find (i->first.type_id ()));
38 if (v != traversal_map_.end ())
40 //wcerr << "dispatching traversers for "
41 // << typeid (n).name () << " as "
42 // << i->first.type_id ().name () << endl;
45 Traversers const& traversers = v->second;
46 for (typename Traversers::const_iterator
47 ti (traversers.begin ()), te (traversers.end ());
50 (*ti)->trampoline (n);
53 flatten_tree (i->first, dispatched);
58 // Remove traversed types from the level map.
62 for (typename TypeInfoSet::const_iterator i = dispatched.begin ();
63 i != dispatched.end ();
73 void DispatcherBase<B>::
79 ExtendedTypeInfo const& ti = extended_type_info (n);
81 unsigned long max = compute_levels (ti, 0, levels);
84 //wcerr << "starting dispatch process for "
85 // << typeid (n).name () << " with "
86 // << max << " levels" << endl;
88 //wcerr << "using " << &traversal_map_ << " traversal map" << endl;
90 for (unsigned long l = 0; l < max + 1; ++l)
92 TypeInfoSet dispatched;
94 for (typename LevelMap::const_iterator
95 i (levels.begin ()), e (levels.end ());
100 typename TraversalMap::const_iterator v (
101 traversal_map_.find (i->first.type_id ()));
103 if (v != traversal_map_.end ())
105 //wcerr << "dispatching traversers for "
106 // << typeid (n).name () << " as "
107 // << i->first.type_id ().name () << endl;
110 Traversers const& traversers = v->second;
111 for (typename Traversers::const_iterator
112 ti (traversers.begin ()), te (traversers.end ());
115 (*ti)->trampoline (n);
118 flatten_tree (i->first, dispatched);
123 // Remove traversed types from the level map.
127 for (typename TypeInfoSet::const_iterator i = dispatched.begin ();
128 i != dispatched.end ();
137 template <typename B>
138 unsigned long DispatcherBase<B>::
139 compute_levels (ExtendedTypeInfo const& ti,
143 unsigned long ret = cur;
145 if (map.find (ti) == map.end () || map[ti] < cur) map[ti] = cur;
147 for (ExtendedTypeInfo::BaseIterator i = ti.begin_base ();
151 unsigned long t = compute_levels (i->type_info (), cur + 1, map);
152 if (t > ret) ret = t;
158 template <typename B>
159 void DispatcherBase<B>::
160 flatten_tree (ExtendedTypeInfo const& ti, TypeInfoSet& set)
164 for (ExtendedTypeInfo::BaseIterator i = ti.begin_base ();
168 flatten_tree (i->type_info (), set);