1 : // Copyright 2011 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // A function for iterating over a changing BlockGraph. Intended for use by
16 : // BlockGraphTransforms.
17 :
18 : #ifndef SYZYGY_BLOCK_GRAPH_ITERATE_H_
19 : #define SYZYGY_BLOCK_GRAPH_ITERATE_H_
20 :
21 : #include "base/callback.h"
22 : #include "syzygy/block_graph/block_graph.h"
23 :
24 m : namespace block_graph {
25 :
26 : // The type of callback used by the IterateBlockGraph function.
27 m : typedef base::Callback<bool(BlockGraph* block_graph,
28 m : BlockGraph::Block*)> IterationCallback;
29 :
30 : // This is an iterating primitive that transforms can make use of. It takes
31 : // care of iterating in such a manner that the callback function may modify the
32 : // block-graph being iterating without worry.
33 : //
34 : // The callback has freedom to modify any block in the block-graph, and to add
35 : // any number of blocks to the block-graph. It is constrained to be allowed
36 : // to delete only the current block being handled by the callback.
37 : //
38 : // The iteration will only visit those blocks that were pre-existing in the
39 : // BlockGraph. That is, if the callback causes new blocks to be generated those
40 : // blocks will never be visited and passed to the callback.
41 : //
42 : // @param callback the callback to invoke for each pre-existing block in the
43 : // block graph.
44 : // @param block_graph the block graph that is to be iterated. This is non
45 : // const as the callback function may modify the block graph as the
46 : // iteration proceeds.
47 m : bool IterateBlockGraph(const IterationCallback& callback,
48 m : BlockGraph* block_graph);
49 :
50 m : } // namespace block_graph
51 :
52 : #endif // SYZYGY_BLOCK_GRAPH_ITERATE_H_
|