systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
typedef_filter.py
Go to the documentation of this file.
1from lark import Tree
2from parselib.transforms import TopDown
3from parselib.transforms.node import TypeDefType
4from ..utils import dprint, is_tree_type, get_ids_in_tree, alternate_ids, set_ids_in_tree_dfs
5
6
8 """This pass recognizes the custom typedef type and remove it from the grammar tree"""
9 def __init__(self):
10 super().__init__()
11 self.types = dict()
12 self.current_params = None
13
14 @staticmethod
15 def _get_type_name(tree):
16 return tree.children[0]
17
18 @staticmethod
20 return list(map(lambda x: x.children[0], tree.find_data('htypetemplateparam')))
21
22 @staticmethod
24 return dict(map(lambda x: (x.children[0], x.children[1]), tree.find_data('htypealias')))
25
26 def htypedef(self, tree):
27 type_name = TypeDefFilter._get_type_name(tree)
28 type_params = TypeDefFilter._get_type_params(tree)
29 type_aliases = TypeDefFilter._get_type_aliases(tree)
30
31 self.current_params = type_params
32 self.__push_up(tree)
33 self.current_params = None
34
35 type_fields = list(tree.find_data('htypefield'))
36 t = TypeDefType(type_name, type_params, type_aliases, type_fields)
37 self.types[type_name] = t
38 return tree
39
40 def hdeptype(self, tree):
41 return tree
42
43 def htypealias(self, tree):
44 dprint(tree)
45 return tree
46
47 def htype(self, tree):
48 # extract type parameters
49 if len(tree.children) == 1 and self.current_params and tree.children[0] in self.current_params:
50 return tree.children[0]
51 else:
52 self.__push_up(tree)
53 return tree
54
55 def start(self, tree):
56 tree.children = self.visit_children(tree)
57 # remove typedefs from the syntax tree
58 tree.children = list(filter(lambda x: x.data != 'typelist', tree.children))
59 return tree
60
61
63 """This pass recognizes the custom typedef type and remove it from the grammar tree"""
64 def __init__(self):
65 super().__init__()
66
67 def htype(self, tree):
68 self.__push_up(tree)
69 if is_tree_type(tree, 'htype') and isinstance(tree.children[0], int):
70 return tree.children[0]
71 return tree
__push_up(self, current_node)
Definition top_down.py:29