]> git.proxmox.com Git - rustc.git/blob - src/binaryen/src/ir/find_all.h
New upstream version 1.23.0+dfsg1
[rustc.git] / src / binaryen / src / ir / find_all.h
1 /*
2 * Copyright 2017 WebAssembly Community Group participants
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef wasm_ir_find_all_h
18 #define wasm_ir_find_all_h
19
20 #include <wasm-traversal.h>
21
22 namespace wasm {
23
24 // Find all instances of a certain node type
25
26 template<typename T>
27 struct FindAll {
28 std::vector<T*> list;
29
30 FindAll(Expression* ast) {
31 struct Finder : public PostWalker<Finder, UnifiedExpressionVisitor<Finder>> {
32 std::vector<T*>* list;
33 void visitExpression(Expression* curr) {
34 if (curr->is<T>()) {
35 (*list).push_back(curr->cast<T>());
36 }
37 }
38 };
39 Finder finder;
40 finder.list = &list;
41 finder.walk(ast);
42 }
43 };
44
45 } // namespace wasm
46
47 #endif // wasm_ir_find_all_h
48