|
2 | 2 | from clang_bind.parse import Parse |
3 | 3 |
|
4 | 4 | FILE = "file.cpp" |
5 | | -ARGS = ["c++14"] |
6 | 5 |
|
7 | 6 |
|
8 | 7 | def parse(tmp_path, file_contents): |
9 | 8 | source_path = tmp_path / FILE |
10 | 9 | with open(source_path, "w") as f: |
11 | 10 | f.write(str(file_contents)) |
12 | 11 |
|
13 | | - tree = Parse(source_path, ARGS).get_tree() # parse the file into an AST |
14 | | - tree_paths = ( |
15 | | - tree.paths_to_leaves() |
16 | | - ) # a list of list of nodes, representing paths from the root node to each leaf |
17 | | - |
18 | | - return tree, tree_paths |
| 12 | + parser = Parse(source_path) |
| 13 | + tree = parser.get_tree() # parse the file into an AST |
| 14 | + tree_paths = [ |
| 15 | + parser.get_parsed_infos_from_node_ids(path) for path in tree.paths_to_leaves() |
| 16 | + ] # a list of list of parsed infos, representing paths from the root node to each leaf |
| 17 | + return parser, tree_paths |
19 | 18 |
|
20 | 19 |
|
21 | 20 | def debug_print(tree, tree_paths): |
@@ -126,16 +125,18 @@ def test_function_decl_with_parameters(tmp_path): |
126 | 125 | file_contents = """ |
127 | 126 | int aFunction(int firstParam, double secondParam); |
128 | 127 | """ |
129 | | - tree, tree_paths = parse(tmp_path=tmp_path, file_contents=file_contents) |
| 128 | + parser, tree_paths = parse(tmp_path=tmp_path, file_contents=file_contents) |
130 | 129 |
|
131 | 130 | function_decl = tree_paths[0][1] |
132 | 131 | assert function_decl.cursor.kind == clang.CursorKind.FUNCTION_DECL |
133 | 132 | assert function_decl.cursor.spelling == "aFunction" |
134 | 133 | assert function_decl.cursor.result_type.kind == clang.TypeKind.INT |
135 | 134 |
|
136 | | - function_decl_children = [ |
137 | | - child.identifier for child in tree.children(function_decl) |
138 | | - ] |
| 135 | + function_decl_children = parser.get_parsed_infos_from_node_ids( |
| 136 | + parser.get_node_ids_from_nodes( |
| 137 | + parser.get_children_nodes_from_parent_parsed_info(function_decl) |
| 138 | + ) |
| 139 | + ) |
139 | 140 |
|
140 | 141 | first_param = function_decl_children[0] |
141 | 142 | assert first_param.cursor.spelling == "firstParam" |
|
0 commit comments